Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Game Programming By Example

You're reading from   Python Game Programming By Example A pragmatic guide for developing your own games with Python

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781785281532
Length 230 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

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 __init__(self, width=400, height=300):
        self.title = 'Hello, Pygame!'
        self.fps = 100
        self.width = width
        self.height = height
        self.circle_pos = width/2, height/2

Pygame uses regular strings for the window title...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime