Drawing with OpenGL

Until now, we have always rendered our objects with a utility routine, but most OpenGL applications require the use of some drawing primitives.

The Cube class

We will define a new class to render cubes, and we will use the following representation to better understand the vertices' positions. From 0 to 7, the vertices are enumerated and represented in a 3D space.

The Cube class

The sides of a cube can now be represented as tuples: the back face is (0, 1, 2, 3), the right face is (4, 5, 1, 0), and so on.

Note that we arrange the vertices in counterclockwise order. As we will learn later, this will help us enable an optimization called face culling ...

Get Python Game Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.