O'Reilly logo

Python Game Programming By Example by Joseph Howse, Alejandro Rodas de Paz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding the Pygame library

With GLUT, we can write OpenGL programs quickly, primarily because it was aimed to provide routines that make learning OpenGL easier. However, the GLUT API was discontinued in 1998. Nonetheless, there are some popular substitutes in the Python ecosystem.

Pygame is one of these alternatives, and we will see that it can be seamlessly integrated with OpenGL, even simplifying the resulting code for the same program.

Pygame 101

Before we integrate Pygame into our OpenGL program, we will write a sample 2D application to get started with Pygame.

We will import Pygame and its locals module, which includes the constants that we will need in our application:

import sys import pygame from pygame.locals import * class App(object): def ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required