This tutorial is based loosely on the NeHe1 tutorial
by Jeff Molofee, though the code is entirely unique to OpenGLContext.
It demonstrates the creation of a basic rendering Context. Note:
OpenGLContext takes care of most of the setup seen in the NeHe code
(though doing so also means that there's less direct control of the
setup process), leaving a very simple core script.
The first thing we do is get a Context class. OpenGLContext provides a "testingcontext" module which allows you to use whatever context-type the user has specified as "prefered". The testingcontext module provides a function "getInteractive" which takes an optional list of the context-name to retrieve, and returns an appropriate Context sub-class and a MainFunction which is called to start the Context's rendering loop.
from OpenGLContext import testingcontext
BaseContext, MainFunction = testingcontext.getInteractive()
We make the standard OpenGL commands available to our code using an
import * statement.
from OpenGL.GL import *
Now we sub-class the BaseContext class we got in stage one with our
own "TestContext" class. In this very simple example this stage is
not actually necessary, as we have no customisations of the class that
we want to do, but it is the "normal" approach to using OpenGLContext
Contexts.
class TestContext( BaseContext ):
"""A subclass of the (dynamically determined) BaseContext,
by overriding various methods, we could customize the
functionality of this context, but the tutorial doesn't
ask us to do this."""
And finally, we make the script run MainFunction with an instance of
our TestContext if the module is run as a script.
if __name__ == "__main__":
## We only want to run the main function if we
## are actually being executed as a script
MainFunction ( TestContext)
You can find the complete code for this sample in
OpenGLContext/tests/nehe1.py