Montag, 19. September 2011

SwipEout - Python + OpenGL ES 2.0 on the N950 (and N900!)

Last weekend I've been toying around with Open GL ES 2.0 on the N950 after finding a nice Xlib-based Python example on the web for the N900. I modified the code a bit, replaced the Xlib code with a QGLWidget from QtOpenGL (via PySide), which makes the setup a lot easier and (apart from API differences of GL ES 2.0 and Desktop GL) allows me to test the prototype on my normal computer as well.

After I got the hang of it, I decided to come up with some fancy 90s-style hover racing game (only texturing, no lighting), or at least parts of it - right now, the small hovercraft just runs around the track and you can shift it left and right via the touchscreen and switching between normal and bird's view by pressing any hardware key.

As for the GL ES bindings (this is the interesting/useful part to developers who want to access the GL ES 2.0 API from Python), I put together a naive header-to-ctypes binding generator for the GL ES 2.0 API which you can run on "gl2.h" from the Qt SDK's Madde sysroot (too lazy to search for a working binding generator that surely exists somewhere out there already) - or just grab the generated "gles2.py" from the SwipEout source tarball. The result? Video it yourself.


You can grab the source code and miscellaneous files from the SwipEout website. The code was tested on the N900 and N950, you only need Python, PIL (python-imaging), PySide and the Open GL ES 2.0 libraries (libGLESv2.so) installed. Removing the PIL dependency and replacing it with Qt-based texture loading is left as an exercise for the reader. Enjoy :)

3 Kommentare:

Anonym hat gesagt…

It doesn't run on my Intel GPU with the Mesa OpenGL ES drivers.

thp hat gesagt…

Anon9EjEvaBU: What is the exact error message that you get? "Doesn't run" isn't really helpful to track down the issue ;)

TheVirtualVortex hat gesagt…

That's brilliant ! I've been hoping and looking for something like that since a long time. Too bad it doesn't work with pygame as pygame can't init a GLES 2 window/context.