Sunday, June 19, 2011

Python, GTK, GL and Incantation.

In computer terms, an “incantation” is a problem that can easily be solved if you know the proper mystical invocation. An incantation is especially annoying if it's something that has to have been done many times before, but no one as bothered to tell we mere mortals how they did it.

Linux suffers incantation at a near mystical level. People who write library code seem to take a sadistic pleasure in not telling people how to use said library.

I ran in to this in spades when I tried to use Python to hook up the OpenGL graphics library to the GTK widget system. I didn't have too much trouble finding examples of hooking GTK to Python, the PyGtk libraries are full of examples. I didn't have too much trouble finding OpenGL examples in Python. Search for “PyOpenGL Demo” and you'll probably find what you need.

My problem came from trying to hook Python, Gtk and OpenGL together as one big happy family. I couldn't find one complete example on the net. I could find some pieces, but no complete example.

To make a long story short, I finally found enough pieces, and read enough source code to have a pretty good idea of how to get the job done. In true Linux fashion it turns out to be pretty easy. The documented code is at my website. Hopefully there is now one less incantation in the world.