pygame is
Simple DirectMedia Layer is
Site Swing
OpenGL Library (glLib*)

OpenGL Library (glLib*) - 1.3

Ian Mallett (geometrian)



I for one got sick of having to figure out how to do everything in PyOpenGL. Don't get me wrong--PyOpenGL is a brilliant module, and usually, it wasn't so hard, but it could have been made easier. Forgot how to turn on texturing, or lighting? Google fifteen minutes and add the one line of code you need. Can't figure out why your polygons don't show up? Start over. Can't remember how to make a quadric sphere? Dredge up some decades old code to search for how.

I decided to change all that and actually make some PyOpenGL basecode for a change, instead of redoing it every time.

This code is the result.

Additionally, this code will let you do things you didn't know how to do before. Do you want to load a heightmap? Do you want to have a nice smooth camera ride? Have you ever done mipmapping? Do you want shadows? Answer: 'Yes'.

So, down to it:
This code should make doing PyOpenGL much easier for most of us. You may use this code anywhere you like, BUT please give my credit for your nice game's backend, and if you explicitly take credit for it, I may have to kill you ;-)

Please note, this is a semi-beta release. Everything works (unless you have an old computer which doesn't like shadowing), but the code is not documented nor particularly stable (it is easy to crash it by doing something bad, and you'll have no idea what happened). That said, the code is designed to be easy to read.

Have fun!


Home Page:


click to view original size


OpenGL Library (glLib*) - 1.4 - Sep 16, 2008
OpenGL Library (glLib*) - 1.3 - Sep 14, 2008 account Comments

If you wish to leave a comment with your account, please sign in first.

January 3, 2011 12:31pm - Ian Mallett - nickname: (geometrian)
Absolutely. Also keep in mind the newest version (as of now, glLib Reloaded) is the result of another two years work, and should be much better for learning purposes.
September 21, 2010 10:44am - Unknown - nickname: (cib) - 5/5
This looks rather amazing. The texturing module already helped me a lot in understanding how to make pygame and pyopengl cooperate! I might be going to use this(or parts of this) in my own library, I understand that's fine with you as long as I give you credits? :)
December 7, 2008 8:45pm - Ian Mallett - nickname: (geometrian)
Check out the new shader version!
November 29, 2008 8:04pm - Ian Mallett - nickname: (geometrian)
Yes, RB[0] is right. :) Mipmapping sometimes does cause weird problems. The number is the antialias level, implemented by combinations of various types of filtering and mipmapping. Passing "0" means no antialiasing, and should fix the problem.

However, you might still get an error where the outside of the shadow is shadowed. That's a bug caused by ATI cards, in which case, you may or may not have a problem. It should be fixed (hopefully) in the shader version of this library, coming soon (I hope). Likely, it would mean manually coding the shader function shapow2DProj(), which I don't relish doing...
November 27, 2008 10:18pm - RB[0] - nickname: (roebros) - 5/5
That is due to some gfx cards not supporting the shadow stuff used here.
A fix is to find the line like this:
In the shadow example code. It should be a 5 or something in there - change it to 0 and it should be fixed up better ;)
The problem has something to do with the mip-mapped textures used when higher anti-alias levels are being used, so this sets it to not do that.

BTW, the lib is really coming along nicely Ian ;)
November 16, 2008 6:42am - Nathan Woodward - nickname: (thedalailama)
Well, that's odd. Turns out it was working without glutInit, it was just rotating really fast and looked like a glitch.

But I'm also getting this dodgy apparition:

Which might or might not be my computer being insane.
November 16, 2008 6:22am - Nathan Woodward - nickname: (thedalailama)
Ah, thanks. I'll give it a go.
November 15, 2008 1:07pm - Ian Mallett - nickname: (geometrian)
Which error? The teapot one? I've done some more research and for some reason my computer is apparently the only one in existence which does not need glutInit() called. So, I can't remember, but if this release gives you some error about teapots or glut or whatnot, you can either not load the teapot, use a different object, or simply add glutInit() to the program (anywhere after "from OpenGL.GLUT import *"should be fine).
November 15, 2008 8:51am - Nathan Woodward - nickname: (thedalailama)
When you say updated the installation to fix the dodginess, do you mean GLUT or pyopengl?

I easy-install'd pyopengl again, and am still getting the error. It's entirely possible I've done something wrong somewhere, though.
October 23, 2008 6:36pm - Ian Mallett - nickname: (geometrian)
I've FINALLY gotten working shaders, so hopefully I can get better amazing code, and hopefully a new release should follow!
September 20, 2008 1:17am - Ian Mallett - nickname: (geometrian)
How strange...
OK, here's a duplicate link:
September 19, 2008 8:12am - Dylan J. Raub - nickname: (dylanjraub)
Hi, could you put the file in a place where I can get it? I can't get to your web site 'cause it's blocked...
September 16, 2008 2:10am - Ian Mallett - nickname: (geometrian)
I added a check on the teapot so it won't crash.
Thanks for the comments all!
Version 1.4 released!
September 15, 2008 10:34pm - Anonymous - nickname: (pywiz32)
this project + blender to python + blender models = awesome game.
September 15, 2008 5:38pm - RB[0] - nickname: (roebros)
Ian, just make sure to call glutInit - that happened to me once ;)
September 15, 2008 3:24pm - Marek Lisy - nickname: (maral)
OK, Thanks
September 15, 2008 3:05pm - Ian Mallett - nickname: (geometrian)
This is the other manifestation of the same error. See my previous post. ;-)
September 15, 2008 1:53pm - Marek Lisy - nickname: (maral) - 3/5
In some of examples i got error:
freeglut ERROR: Function <glutSolidTeapot> called without first calling 'glutInit'.
Thanks for answer.
September 15, 2008 10:46am - Romuald - nickname: (romu89)
Awesome, thanks for reply, now it works :)
September 15, 2008 4:24am - Ian Mallett - nickname: (geometrian)
This could technically be fixed within my code, but I think it is a GLUT version problem. Update your installation, as I believe that should fix the problem (I don't get the error, for instance). For a quick fix, just comment out the teapot bit, glLibObjTeapot(), in the various examples (i.e., don't try loading it).
September 15, 2008 2:42am - Romuald - nickname: (romu89)

Your project seems cool, but I got the following error :

"OpenGL.error.NullFunctionError: Attempt to call an undefined function glutSolidT
eapot, check for bool(glutSolidTeapot) before calling"

I tried it on Vista, after correctly installed PyOpenGL.
September 14, 2008 12:39am - Ian Mallett - nickname: (geometrian)
Version 1.3 released! (Versions 1-1.2 were pre-release work)

our projects welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
recent releases
May 22, 2016

May 21, 2016

May 18, 2016

May 1, 2016

Mar 27, 2016

Mar 26, 2016

Mar 22, 2016

Mar 19, 2016

Mar 17, 2016

... more!
for pygame related questions, comments, and suggestions, please see help (lists, irc)