Illusion of motion produced by rapidly displaying still frames that change

Animation frame rate can be independent of video display frequency

Traditional animation often worked at 12 frames per second.
But faster rates will yield smoother motion.

Below ~ 10 fps, animation looks like a slide show, rather than motion

Programming Model

An animated, interactive computer graphics program usually includes:

A framework often defines a standard structure for the code.

Animation is virtually never handled by an explicit loop in our own code.

OpenGL Functions

GL function names follow a standardized scheme

All begin with "gl", followed by the basic name of the command

When there's only one possible form of arguments:

OpenGL Functions

When arguments can take multiple forms:

e.g. the Color function has the forms:

OpenGL Constants

Constants are defined for certain function arguments

Constant names are all in capital letters, in the form:

e.g. possible arguments for glBegin() are:


OpenGL consists of commands related to drawing 2D & 3D objects (e.g. draw a triangle, define material properties, define a texture).

Drawing has to be done in some sort of window, controlled by the operating system.

OpenGL avoids including any sort of functions to create or manipulate windows, to handle input devices (keyboard, mouse, etc), or to read image data from files (JPEG, PNG, MOV, etc)

Other programming toolkits must be used to take care of these other tasks. For example, SDL, GLUT, pygame, or pyglet.

pyglet provides a cross-platform framework for windowing, input, multimedia, and text display.

Pyglet functions can be used under Linux, MacOS, and Windows without changing your code.

Pyglet Program Structure

Pyglet provides an "app" object as the basis for program execution. It runs an event loop, with callback functions.

callback - a function that you provide for other code to call when needed; the "other code" is typically in a library

Callbacks are used for for drawing, keyboard & mouse input, and other events.

Whenever the window must be redrawn, your drawing function is called.
Whenever a key is pressed, your keyboard function is called.

Pyglet Example

# Minimal program to open & clear a window.
# This program is intended to introduce pyglet program structure

import sys
from import *

window = pyglet.window.Window()

def on_draw():

OpenGL Pipeline


Creative Commons License
This document is by Dave Pape, and is released under a Creative Commons License.