3D Graphics with Pygame


March 19, 2011 Code on Github

Contents

In this tutorial I hope to explain the basics of 3D graphics using Python and Pygame. Pygame is not really designed for 3D graphics, so if you want to create a game with 3D graphics, you'd be better off using something else where all the basics, such as shading, are done automatically.

The aim of this tutorial is primarily to explain the mathematics of 3D graphics. I'm using Pygame to display the results simply because it's convenient. Hopefully, however, some of the programs might be useful in their own right.

I have also written a tutorial using the HTML5 canvas and Javascript. That version was written after this one, so is probably better, though this uses matrices.

Examples

Here are some examples of what is possible. These aren't yet covered by the tutorial, but who knows, one day I might add them. You can find the code for these example here.

Some simple animation

Reading .obj files

Shading

Some simple physics