This document discusses the NeHe3 tutorial by Jeff Molofee. It adds glColor-based colors to the geometry-rendering introduced in NeHe2.
See NeHe2 for discussion of the Context
setup procedure here...
from OpenGLContext import testingcontext
BaseContext, MainFunction = testingcontext.getInteractive()
from OpenGL.GL import *
class TestContext( BaseContext ):
# set initial camera position, tutorial does the re-positioning
initialPosition = (0,0,0)
def Render( self, mode = 0):
"""Render the geometry for the scene."""
BaseContext.Render( self, mode )
glDisable( GL_CULL_FACE )
By default OpenGLContext enables lighting. The tutorial assumes that lighting is disabled, so we disable it. If we didn't do so, you wouldn't see the colours applied to the geometry. See glColorMaterial for an explanation of why this is so.
glDisable( GL_LIGHTING)
The rest of the Render function is taken from the original NeHe
tutorial.
glTranslatef(-1.5,0.0,-6.0);
glBegin(GL_TRIANGLES)
glColor3f(1,0,0)
glVertex3f( 0.0, 1.0, 0.0)
glColor3f(0,1,0)
glVertex3f(-1.0, -1.0, 0.0)
glColor3f(0,0,1)
glVertex3f( 1.0, -1.0, 0.0)
glEnd()
glTranslatef(3.0,0.0,0.0);
glColor3f(0.5,0.5,1.0)
glBegin(GL_QUADS)
glVertex3f(-1.0,-1.0, 0.0)
glVertex3f( 1.0,-1.0, 0.0)
glVertex3f( 1.0, 1.0, 0.0)
glVertex3f(-1.0, 1.0, 0.0)
glEnd()
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/nehe3.py