Examples Of using PyGame and PyOpenGL for 2d game graphics
I've been playing with PyGame and PyOpenGL for a bit over a year and a
half, and I would like to share what I have learnt. My focus has
been on creating 2d sprite based games using OpenGL rendering.
In these articles, I will walk through the process of building up a framework for making 2d games using PyOpenGL and Python. I assume that the reader knows Python, and has some familiarity with OpenGL.
Why OpenGL instead of SDL surfaces in PyGame? It's easy to get
hardware acceleration using OpenGL, and OpenGL has more powerful graphics manipulating abilities. The extra power comes with
extra complexity though. Hence these articles on how I simplify
things.
While I do my best to explain what the code is doing, but to really understand the functions used the PyGame and PyOpenGL documentation are great resources.
Example1 - The humble beginning. Creating a window, drawing a triangle, and listening for an exit signal.
Example2a - We add functions to load an image to a texture, and to render it efficiently.
Example2b - Next we wrap the texture function in a object class with some additional functionality.
Example3a - This example adds creating text messages on textures.
Example3b - Then we take the new functionality from 3a and wrap
it in a class that is very similar to what we created in 2b.
ExampleSource.tgz - Download the source files for all of the above examples.