OpenGLContext: A Learning Environment for PyOpenGL

OpenGLContext provides you with an environment for learning OpenGL programming.  It gives you an object-oriented Python-friendly set of services which let you concentrate on your OpenGL code instead of the underlying GUI environment.


Note: This page discusses OpenGLContext 1.0.  You almost certainly want to be using OpenGLContext 2.0

Installation

OpenGLContext is dependent on having at least the 2.0 release of PyOpenGL.  PyOpenGL and OpenGLContext can be downloaded from the PyOpenGL project.  OpenGLContext uses many of the OpenGL 1.1 features, and provides a GLUT 3.7 context, so you'll want to be sure you have those.

You will need to install Numeric Python (version 19+ if possible), and the Python Imaging Library.  Once you have these dependencies installed, you can install the OpenGLContext package.

OpenGLContext is distributed as a distutils-enabled Python extension archive.  Setup consists of unpacking the .zip archive into a temporary directory and running python setup.py install.  This will install the OpenGLContext package in your site's standard package directory.

Structural Overview of OpenGLContext

Within the top-level OpenGLContext package are the objects implementing the Context interface. Each supported GUI library defines a derived Context class which overrides various methods to support the Context API (these derived classes are named GLUTContext, PyGameContext, wxContext, etceteras).  Each supported GUI will also provide a sub-class which uses the mix in InteractiveContext, which, through the events package (see below), allows for keyboard and mouse event processing.  Each GUI library will then provide a module Xtestingcontext.py (e.g. gluttestingcontext.py) which provides a context class factory function, and a "mainloop" function. The testingcontext.py module then provides an interface for finding the appropriate testing context for the specified GUI library.

Each Context class has a list of associated RenderMode objects, which implement the various rendering mode algorithms common in OpenGL.  Currently there are Timer, Opaque, Transparent, and Select modes available, and all default Contexts include all four.

On each visible rendering pass, the Opaque RenderMode creates a RenderPass object which stores pass-specific information such as the events needing selection processing and the "default" matrices for projections.

The ViewPlatform and ViewPlatformMixin classes provide a simple navigation interface using the keyboard arrow keys (walk/fly) and the ALT-arrow keys (pan/slide).  These classes make use of the Trackball, ExamineManager and DragWatcher classes as well.

Finally, at the top-level, we have a number of utility functions and modules, including drawcube (a testing function), Quaternion, utilities, vector utilities, and triangle utilities.

The scenegraph and scenegraph.text packages provide a set of Python classes which render certain common types of geometry, materials, textures and grouping nodes (modeled loosely after VRML 97 nodes). This allows you to create "retained mode" scenes for rendering in your contexts (note that these classes are largely divorced from the internals of the context). You'll find Transform (including integer "names" reported during selection), Shape, Material, ImageTexture, and Light nodes which are similar to their VRML 97 namesakes.  The ArrayGeometry class handles the rendering of all of IndexedFaceSet, IndexedLineSet and PointSet, with the modules of those names simply instantiating ArrayGeometry instances with the appropriate parameters.  The text package is just a placeholder until PyOpenGL adds text support (which it will hopefully do after the 2.0 release).

The events package implements a simple cross GUI-library event generation and handling system.  Each GUI library defines subclasses of the major event and event handler classes.  These subclasses translate from native events to OpenGLContext events. The event handler classes (which are mixin classes) are then included in the GUI library's Context class to provide the event handling interfaces.

Introductory Documentation

Rendering Geometry
Render geometry manually and using the OpenGLContext.scenegraph package.  Includes coverage of the Shape and Material classes for specifying geometry surface characteristics.
Working with Images and Textures
Use PIL and Numeric Python to load, save and manipulate images for use as PyOpenGL textures.  Generate textures with various attributes such as filtering and mip-mapping.
Using Numeric Python
Create and manipulate Numeric Python arrays.  Use Numeric Python arrays to efficiently specify geometry for rendering.
Working with the Mouse
Use OpenGLContext's event mechanisms to create interactive objects which respond to the user's pointer.
Working with Navigation
Understand and work with OpenGLContext's navigation modes.  Define your own navigation modes.
Working with Timers
Use OpenGLContext's timer event system to animate objects and events within the system.

Reference Documentation

Sample and Testing Code
The OpenGLContext/tests package holds  a considerable number of test and demonstration modules.  These should likely be your first stop for getting a feeling for OpenGLContext.
PyOpenGL Documentation Collection
Links to PyOpenGL-specific and generic documentation around the Internet.
Python Imaging Library Handbook
OpenGLContext makes use of the Python Imaging Library (PIL).  You'll want to download the library, and, if you have any wish to do image processing with PyOpenGL, you may want to familiarize yourself with the package's documentation.
Numeric Python Handbook
PyOpenGL and OpenGLContext make extensive use of the Numeric Python multidimensional array type.  You will want to familiarize yourself with this documentation to be able to understand the matrix-manipulation code used throughout OpenGLContext. Note: other documentation for Numeric Python is available from the Numeric Python homepage.
A SourceForge Open-Source Project: