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.
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:
When arguments can take multiple forms:
e.g. the Color function has the forms:
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 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.
# Minimal program to open & clear a window. # This program is intended to introduce pyglet program structure import sys from pyglet.gl import * window = pyglet.window.Window() @window.event def on_draw(): glClearColor(0,0,0,0) glClear(GL_COLOR_BUFFER_BIT) pyglet.app.run()