def __init__(self, *args, **kwargs): global mShadowMatrix window.Window.__init__(self, *args, **kwargs) # pyglet reverses y axis vPoints = (M3DVector3f * 3)((0.0, -0.4, 0.0), (10.0, -0.4, 0.0), (5.0, -0.4, -5.0) ) # Grayish background glClearColor(fLowLight[0], fLowLight[1], fLowLight[2], fLowLight[3]) # Clear stencil buffer with zero, increment by one whenever anybody # draws into it. When stencil function is enabled, only write where # stencil value is zero. This prevents the transparent shadow from drawing # over itself glStencilOp(GL_INCR, GL_INCR, GL_INCR) glClearStencil(0) glStencilFunc(GL_EQUAL, 0x0, 0x01) # Cull backs of polygons glCullFace(GL_BACK) glFrontFace(GL_CCW) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) glEnable(GL_MULTISAMPLE_ARB) # Setup light parameters glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fNoLight) glLightfv(GL_LIGHT0, GL_AMBIENT, fLowLight) glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight) glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) # TODO: this doesn't seem to be enough to make this work on my computer? glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR) # Calculate shadow matrix pPlane = m3dGetPlaneEquation(vPoints[0], vPoints[1] , vPoints[2]) mShadowMatrix = m3dMakePlanarShadowMatrix(pPlane, fLightPos) # Mostly use material tracking glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight) glMateriali(GL_FRONT, GL_SHININESS, 128) # Randomly place sphere inhabitants for sphere in spheres: # Pick a random location between -20 and 20 at .1 increments sphere.setOrigin(float(randint(-200, 200)) * 0.1, 0.0, float(randint(-200, 200)) * 0.1)
def __init__(self, *args, **kwargs): global mShadowMatrix window.Window.__init__(self, *args, **kwargs) # Calculate shadow matrix vPoints = (M3DVector3f * 3)((0.0, -0.4, 0.0), (10.0, -0.4, 0.0), (5.0, -0.4, -5.0)) # Grayish background glClearColor(fLowLight[0], fLowLight[1], fLowLight[2], fLowLight[3]) # Setup Fog parameters glEnable(GL_FOG) # Turn Fog on glFogfv(GL_FOG_COLOR, fLowLight) # Set fog color to match background glFogf(GL_FOG_START, 5.0) # How far away does the fog start glFogf(GL_FOG_END, 30.0) # How far away does the fog stop glFogi(GL_FOG_MODE, GL_LINEAR) # Which fog equation do I use? # Cull backs of polygons glCullFace(GL_BACK) glFrontFace(GL_CCW) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) # Setup light parameters glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fNoLight) glLightfv(GL_LIGHT0, GL_AMBIENT, fLowLight) glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight) glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) # Get the plane equation from three points on the ground vPlaneEquation = m3dGetPlaneEquation(vPoints[0], vPoints[1], vPoints[2]) # Calculate projection matrix to draw shadown on the ground mShadowMatrix = m3dMakePlanarShadowMatrix(vPlaneEquation, fLightPos) # Mostly use material tracking glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glMateriali(GL_FRONT, GL_SHININESS, 128) # Randomly place sphere inhabitants for sphere in spheres: # Pick a random location between -20 and 20 at .1 increments sphere.setOrigin( float(randint(-200, 200)) * 0.1, 0.0, float(randint(-200, 200)) * 0.1)
def __init__(self, *args, **kwargs): global mShadowMatrix window.Window.__init__(self, *args, **kwargs) # Calculate shadow matrix vPoints = (M3DVector3f * 3)((0.0, -0.4, 0.0), (10.0, -0.4, 0.0), (5.0,-0.4, -5.0) ) # Grayish background glClearColor(fLowLight[0], fLowLight[1], fLowLight[2], fLowLight[3]) # Setup Fog parameters glEnable(GL_FOG) # Turn Fog on glFogfv(GL_FOG_COLOR, fLowLight) # Set fog color to match background glFogf(GL_FOG_START, 5.0) # How far away does the fog start glFogf(GL_FOG_END, 30.0) # How far away does the fog stop glFogi(GL_FOG_MODE, GL_LINEAR) # Which fog equation do I use? # Cull backs of polygons glCullFace(GL_BACK) glFrontFace(GL_CCW) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) # Setup light parameters glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fNoLight) glLightfv(GL_LIGHT0, GL_AMBIENT, fLowLight) glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight) glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) # Get the plane equation from three points on the ground vPlaneEquation = m3dGetPlaneEquation(vPoints[0], vPoints[1] , vPoints[2]) # Calculate projection matrix to draw shadown on the ground mShadowMatrix = m3dMakePlanarShadowMatrix(vPlaneEquation, fLightPos) # Mostly use material tracking glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glMateriali(GL_FRONT, GL_SHININESS, 128) # Randomly place sphere inhabitants for sphere in spheres: # Pick a random location between -20 and 20 at .1 increments sphere.setOrigin(float(randint(-200, 200)) * 0.1, 0.0, float(randint(-200, 200)) * 0.1)
def __init__(self, *args, **kwargs): global shadowMat window.Window.__init__(self, *args, **kwargs) # Any three points on the ground (counter clockwise order) points = [ M3DVector3f(-30.0, -149.0, -20.0), M3DVector3f(-30.0, -149.0, 20.0), M3DVector3f(40.0, -149.0, 20.0) ] glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) # Do not calculate inside of jet glFrontFace(GL_CCW) # Counter clock-wise polygons face out # Enable Lighting glEnable(GL_LIGHTING) # Setup and enable light 0 glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight) glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight) glLightfv(GL_LIGHT0, GL_SPECULAR, specular) glLightfv(GL_LIGHT0, GL_POSITION, lightPos) glEnable(GL_LIGHT0) # Enable color tracking glEnable(GL_COLOR_MATERIAL) # Set Material properties to follow glColor values glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) # All materials hereafter have full specular reflectivity # with a high shine glMaterialfv(GL_FRONT, GL_SPECULAR, specref) glMateriali(GL_FRONT, GL_SHININESS, 128) # light blue background glClearColor(0.0, 0.0, 1.0, 1.0) # Get the plane equation from three points on the ground vPlaneEquation = m3dGetPlaneEquation(points[0], points[1], points[2]) # Calculate projection matrix to draw shadow on the ground shadowMat = m3dMakePlanarShadowMatrix(vPlaneEquation, lightPos) glEnable(GL_NORMALIZE)
def __init__(self, *args, **kwargs): global shadowMat window.Window.__init__(self, *args, **kwargs) # Any three points on the ground (counter clockwise order) points = [ M3DVector3f(-30.0, -149.0, -20.0), M3DVector3f(-30.0, -149.0, 20.0), M3DVector3f(40.0, -149.0, 20.0) ] glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) # Do not calculate inside of jet glFrontFace(GL_CCW) # Counter clock-wise polygons face out # Enable Lighting glEnable(GL_LIGHTING) # Setup and enable light 0 glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight) glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight) glLightfv(GL_LIGHT0, GL_SPECULAR, specular) glLightfv(GL_LIGHT0,GL_POSITION,lightPos) glEnable(GL_LIGHT0) # Enable color tracking glEnable(GL_COLOR_MATERIAL) # Set Material properties to follow glColor values glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) # All materials hereafter have full specular reflectivity # with a high shine glMaterialfv(GL_FRONT, GL_SPECULAR, specref) glMateriali(GL_FRONT, GL_SHININESS, 128) # light blue background glClearColor(0.0, 0.0, 1.0, 1.0) # Get the plane equation from three points on the ground vPlaneEquation = m3dGetPlaneEquation(points[0], points[1], points[2]) # Calculate projection matrix to draw shadow on the ground shadowMat = m3dMakePlanarShadowMatrix(vPlaneEquation, lightPos) glEnable(GL_NORMALIZE)
def InitGL(Width, Height): global mShadowMatrix # Calculate shadow matrix vPoints = (M3DVector3f * 3)((0.0, -0.4, 0.0), (10.0, -0.4, 0.0), (5.0, -0.4, -5.0)) # Grayish background glClearColor(fLowLight[0], fLowLight[1], fLowLight[2], fLowLight[3]) # Cull backs of polygons glCullFace(GL_BACK) glFrontFace(GL_CCW) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) # Setup light parameters glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fNoLight) glLightfv(GL_LIGHT0, GL_AMBIENT, fLowLight) glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight) glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) # Get the plane equation from three points on the ground vPlaneEquation = m3dGetPlaneEquation(vPoints[0], vPoints[1], vPoints[2]) # Calculate projection matrix to draw shadown on the ground mShadowMatrix = m3dMakePlanarShadowMatrix(vPlaneEquation, fLightPos) # Mostly use material tracking glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glMateriali(GL_FRONT, GL_SHININESS, 128) # Randomly place sphere inhabitants for sphere in spheres: # Pick a random location between -20 and 20 at .1 increments sphere.setOrigin( float(randint(-200, 200)) * 0.1, 0.0, float(randint(-200, 200)) * 0.1) glEnable(GL_MULTISAMPLE) # This is actually on by default
def __init__(self, *args, **kwargs): global mShadowMatrix window.Window.__init__(self, *args, **kwargs) # Calculate shadow matrix vPoints = (M3DVector3f * 3)((0.0, -0.4, 0.0), (10.0, -0.4, 0.0), (5.0,-0.4, -5.0) ) glEnable(GL_MULTISAMPLE_ARB) # Grayish background glClearColor(fLowLight[0], fLowLight[1], fLowLight[2], fLowLight[3]) # Clear stencil buffer with zero, increment by one whenever anybody # draws into it. When stencil function is enabled, only write where # stencil value is zero. This prevents the transparent shadow from drawing # over itself glStencilOp(GL_INCR, GL_INCR, GL_INCR) glClearStencil(0) glStencilFunc(GL_EQUAL, 0x0, 0x01) # Setup Fog parameters glEnable(GL_FOG) glFogfv(GL_FOG_COLOR, fLowLight) glFogi(GL_FOG_MODE, GL_LINEAR) glFogf(GL_FOG_START, 5.0) glFogf(GL_FOG_END, 30.0) glHint(GL_FOG_HINT, GL_NICEST) # Cull backs of polygons glCullFace(GL_BACK) glFrontFace(GL_CCW) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) # already enabled this... but superbible code has it here, too glEnable(GL_MULTISAMPLE_ARB) # Setup light parameters glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fNoLight) glLightfv(GL_LIGHT0, GL_AMBIENT, fLowLight) glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight) glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) # Get the plane equation from three points on the ground vPlaneEquation = m3dGetPlaneEquation(vPoints[0], vPoints[1] , vPoints[2]) # Calculate projection matrix to draw shadown on the ground mShadowMatrix = m3dMakePlanarShadowMatrix(vPlaneEquation, fLightPos) # Mostly use material tracking glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glMateriali(GL_FRONT, GL_SHININESS, 128) # Randomly place sphere inhabitants for sphere in spheres: # Pick a random location between -20 and 20 at .1 increments sphere.setOrigin(float(randint(-200, 200)) * 0.1, 0.0, float(randint(-200, 200)) * 0.1)
def on_draw(self): mCubeTransform = M3DMatrix44f() # Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glShadeModel(GL_SMOOTH) glEnable(GL_NORMALIZE) glPushMatrix() # Draw plane that the cube rests on glDisable(GL_LIGHTING) if nStep == 5: glColor3ub(255, 255, 255) glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D, textures[0]) glBegin(GL_QUADS) glTexCoord2f(0.0, 0.0) glVertex3f(-100.0, -25.3, -100.0) glTexCoord2f(0.0, 1.0) glVertex3f(-100.0, -25.3, 100.0) glTexCoord2f(1.0, 1.0) glVertex3f(100.0, -25.3, 100.0) glTexCoord2f(1.0, 0.0) glVertex3f(100.0, -25.3, -100.0) glEnd() else: glColor3f(0.0, 0.0, 0.90) # Blue glBegin(GL_QUADS) glVertex3f(-100.0, -25.3, -100.0) glVertex3f(-100.0, -25.3, 100.0) glVertex3f(100.0, -25.3, 100.0) glVertex3f(100.0, -25.3, -100.0) glEnd() # Set drawing color to Red glColor3f(1.0, 0.0, 0.0) # Enable, disable lighting if nStep > 2: glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glEnable(GL_COLOR_MATERIAL) glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse) glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glMaterialfv(GL_FRONT, GL_SPECULAR, lightSpecular) glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColor) glMateriali(GL_FRONT, GL_SHININESS, 128) # Move the cube slightly forward and to the left glTranslatef(-10.0, 0.0, 10.0) if nStep == 0: # Just draw the wire framed cube glutWireCube(50.0) # Same wire cube with hidden line removal simulated elif nStep == 1: # Front Face (before rotation) glBegin(GL_LINES) glVertex3f(25.0, 25.0, 25.0) glVertex3f(25.0, -25.0, 25.0) glVertex3f(25.0, -25.0, 25.0) glVertex3f(-25.0, -25.0, 25.0) glVertex3f(-25.0, -25.0, 25.0) glVertex3f(-25.0, 25.0, 25.0) glVertex3f(-25.0, 25.0, 25.0) glVertex3f(25.0, 25.0, 25.0) glEnd() # Top of cube glBegin(GL_LINES) # Front Face glVertex3f(25.0, 25.0, 25.0) glVertex3f(25.0, 25.0, -25.0) glVertex3f(25.0, 25.0, -25.0) glVertex3f(-25.0, 25.0, -25.0) glVertex3f(-25.0, 25.0, -25.0) glVertex3f(-25.0, 25.0, 25.0) glVertex3f(-25.0, 25.0, 25.0) glVertex3f(25.0, 25.0, 25.0) glEnd() # Last two segments for effect glBegin(GL_LINES) glVertex3f(25.0, 25.0, -25.0) glVertex3f(25.0, -25.0, -25.0) glVertex3f(25.0, -25.0, -25.0) glVertex3f(25.0, -25.0, 25.0) glEnd() # Uniform colored surface, looks 2D and goofey elif nStep == 2: glutSolidCube(50.0) elif nStep == 3: glutSolidCube(50.0) # Draw a shadow with some lighting elif nStep == 4: glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform) glutSolidCube(50.0) glPopMatrix() # Disable lighting, we'll just draw the shadow as black glDisable(GL_LIGHTING) glPushMatrix() pPlane = m3dGetPlaneEquation(ground[0], ground[1], ground[2]) mCubeTransform = m3dMakePlanarShadowMatrix(pPlane, vLightPos) #MakeShadowMatrix(ground, lightpos, cubeXform) glMultMatrixf(mCubeTransform) glTranslatef(-10.0, 0.0, 10.0) # Set drawing color to Black glColor3f(0.0, 0.0, 0.0) glutSolidCube(50.0) elif nStep == 5: glColor3ub(255, 255, 255) glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform) # Front Face (before rotation) glBindTexture(GL_TEXTURE_2D, textures[1]) glBegin(GL_QUADS) glTexCoord2f(1.0, 1.0) glVertex3f(25.0, 25.0, 25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0, -25.0, 25.0) glTexCoord2f(0.0, 0.0) glVertex3f(-25.0, -25.0, 25.0) glTexCoord2f(0.0, 1.0) glVertex3f(-25.0, 25.0, 25.0) glEnd() # Top of cube glBindTexture(GL_TEXTURE_2D, textures[2]) glBegin(GL_QUADS) # Front Face glTexCoord2f(0.0, 0.0) glVertex3f(25.0, 25.0, 25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0, 25.0, -25.0) glTexCoord2f(1.0, 1.0) glVertex3f(-25.0, 25.0, -25.0) glTexCoord2f(0.0, 1.0) glVertex3f(-25.0, 25.0, 25.0) glEnd() # Last two segments for effect glBindTexture(GL_TEXTURE_2D, textures[3]) glBegin(GL_QUADS) glTexCoord2f(1.0, 1.0) glVertex3f(25.0, 25.0, -25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0, -25.0, -25.0) glTexCoord2f(0.0, 0.0) glVertex3f(25.0, -25.0, 25.0) glTexCoord2f(0.0, 1.0) glVertex3f(25.0, 25.0, 25.0) glEnd() glPopMatrix() # Disable lighting, we'll just draw the shadow as black glDisable(GL_LIGHTING) glDisable(GL_TEXTURE_2D) glPushMatrix() pPlane = m3dGetPlaneEquation(ground[0], ground[1], ground[2]) mCubeTransform = m3dMakePlanarShadowMatrix(pPlane, vLightPos) glMultMatrixf(mCubeTransform) glTranslatef(-10.0, 0.0, 10.0) # Set drawing color to Black glColor3f(0.0, 0.0, 0.0) glutSolidCube(50.0) glPopMatrix()
def InitGL(Width, Height): global mShadowMatrix # pyglet reverses y axis vPoints = (M3DVector3f * 3)((0.0, -0.4, 0.0), (10.0, -0.4, 0.0), (5.0,-0.4, -5.0) ) # Grayish background glClearColor(fLowLight[0], fLowLight[1], fLowLight[2], fLowLight[3]) # Clear stencil buffer with zero, increment by one whenever anybody # draws into it. When stencil function is enabled, only write where # stencil value is zero. This prevents the transparent shadow from drawing # over itself glStencilOp(GL_INCR, GL_INCR, GL_INCR) glClearStencil(0) glStencilFunc(GL_EQUAL, 0x0, 0x01) # Cull backs of polygons glCullFace(GL_BACK) glFrontFace(GL_CCW) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) glEnable(GL_MULTISAMPLE_ARB) # Setup light parameters glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fNoLight) glLightfv(GL_LIGHT0, GL_AMBIENT, fLowLight) glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight) glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) # TODO: this doesn't seem to be enough to make this work on my computer? glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR) # Calculate shadow matrix pPlane = m3dGetPlaneEquation(vPoints[0], vPoints[1] , vPoints[2]) mShadowMatrix = m3dMakePlanarShadowMatrix(pPlane, fLightPos) # Mostly use material tracking glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight) glMateriali(GL_FRONT, GL_SHININESS, 128) # Randomly place sphere inhabitants for sphere in spheres: # Pick a random location between -20 and 20 at .1 increments sphere.setOrigin(float(randint(-200, 200)) * 0.1, 0.0, float(randint(-200, 200)) * 0.1) # Set up texture maps glEnable(GL_TEXTURE_2D) glGenTextures(NUM_TEXTURES, textureObjects) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) for iLoop in range(0, NUM_TEXTURES): glBindTexture(GL_TEXTURE_2D, textureObjects[iLoop]) # Load this texture map img = Image.open(szTextureFiles[iLoop]).convert("RGB") raw_image = img.tobytes() gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, img.width, img.height, GL_RGB, GL_UNSIGNED_BYTE, raw_image) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) # Create display lists firstlist = glGenLists(3) groundList = GLuint(firstlist) sphereList = GLuint(firstlist + 1) torusList = GLuint(firstlist + 2) print (firstlist) # Create sphere display list glNewList(sphereList, GL_COMPILE) glutSolidSphere(0.1, 40, 20) glEndList() # Create torus display list glNewList(torusList, GL_COMPILE) gltDrawTorus(0.35, 0.15, 61, 37) glEndList() # Create the ground display list glNewList(groundList, GL_COMPILE) DrawGround() glEndList()
def on_draw(self): mCubeTransform = M3DMatrix44f() # Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glShadeModel(GL_SMOOTH) glEnable(GL_NORMALIZE) glPushMatrix() # Draw plane that the cube rests on glDisable(GL_LIGHTING) if nStep == 5: glColor3ub(255,255,255) glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D, textures[0]) glBegin(GL_QUADS) glTexCoord2f(0.0, 0.0) glVertex3f(-100.0, -25.3, -100.0) glTexCoord2f(0.0, 1.0) glVertex3f(-100.0, -25.3, 100.0) glTexCoord2f(1.0, 1.0) glVertex3f(100.0, -25.3, 100.0) glTexCoord2f(1.0, 0.0) glVertex3f(100.0, -25.3, -100.0) glEnd() else: glColor3f(0.0, 0.0, 0.90) # Blue glBegin(GL_QUADS) glVertex3f(-100.0, -25.3, -100.0) glVertex3f(-100.0, -25.3, 100.0) glVertex3f(100.0, -25.3, 100.0) glVertex3f(100.0, -25.3, -100.0) glEnd() # Set drawing color to Red glColor3f(1.0, 0.0, 0.0) # Enable, disable lighting if nStep > 2: glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glEnable(GL_COLOR_MATERIAL) glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse) glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glMaterialfv(GL_FRONT, GL_SPECULAR,lightSpecular) glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColor) glMateriali(GL_FRONT, GL_SHININESS,128) # Move the cube slightly forward and to the left glTranslatef(-10.0, 0.0, 10.0) if nStep == 0: # Just draw the wire framed cube glutWireCube(50.0) # Same wire cube with hidden line removal simulated elif nStep == 1: # Front Face (before rotation) glBegin(GL_LINES) glVertex3f(25.0,25.0,25.0) glVertex3f(25.0,-25.0,25.0) glVertex3f(25.0,-25.0,25.0) glVertex3f(-25.0,-25.0,25.0) glVertex3f(-25.0,-25.0,25.0) glVertex3f(-25.0,25.0,25.0) glVertex3f(-25.0,25.0,25.0) glVertex3f(25.0,25.0,25.0) glEnd() # Top of cube glBegin(GL_LINES) # Front Face glVertex3f(25.0,25.0,25.0) glVertex3f(25.0,25.0,-25.0) glVertex3f(25.0,25.0,-25.0) glVertex3f(-25.0,25.0,-25.0) glVertex3f(-25.0,25.0,-25.0) glVertex3f(-25.0,25.0,25.0) glVertex3f(-25.0,25.0,25.0) glVertex3f(25.0,25.0,25.0) glEnd() # Last two segments for effect glBegin(GL_LINES) glVertex3f(25.0,25.0,-25.0) glVertex3f(25.0,-25.0,-25.0) glVertex3f(25.0,-25.0,-25.0) glVertex3f(25.0,-25.0,25.0) glEnd() # Uniform colored surface, looks 2D and goofey elif nStep == 2: glutSolidCube(50.0) elif nStep == 3: glutSolidCube(50.0) # Draw a shadow with some lighting elif nStep == 4: glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform) glutSolidCube(50.0) glPopMatrix() # Disable lighting, we'll just draw the shadow as black glDisable(GL_LIGHTING) glPushMatrix() pPlane = m3dGetPlaneEquation(ground[0], ground[1], ground[2]) mCubeTransform = m3dMakePlanarShadowMatrix(pPlane, vLightPos) #MakeShadowMatrix(ground, lightpos, cubeXform) glMultMatrixf(mCubeTransform) glTranslatef(-10.0, 0.0, 10.0) # Set drawing color to Black glColor3f(0.0, 0.0, 0.0) glutSolidCube(50.0) elif nStep == 5: glColor3ub(255,255,255) glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform) # Front Face (before rotation) glBindTexture(GL_TEXTURE_2D, textures[1]) glBegin(GL_QUADS) glTexCoord2f(1.0, 1.0) glVertex3f(25.0,25.0,25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0,-25.0,25.0) glTexCoord2f(0.0, 0.0) glVertex3f(-25.0,-25.0,25.0) glTexCoord2f(0.0, 1.0) glVertex3f(-25.0,25.0,25.0) glEnd() # Top of cube glBindTexture(GL_TEXTURE_2D, textures[2]) glBegin(GL_QUADS) # Front Face glTexCoord2f(0.0, 0.0) glVertex3f(25.0,25.0,25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0,25.0,-25.0) glTexCoord2f(1.0, 1.0) glVertex3f(-25.0,25.0,-25.0) glTexCoord2f(0.0, 1.0) glVertex3f(-25.0,25.0,25.0) glEnd() # Last two segments for effect glBindTexture(GL_TEXTURE_2D, textures[3]) glBegin(GL_QUADS) glTexCoord2f(1.0, 1.0) glVertex3f(25.0,25.0,-25.0) glTexCoord2f(1.0, 0.0) glVertex3f(25.0,-25.0,-25.0) glTexCoord2f(0.0, 0.0) glVertex3f(25.0,-25.0,25.0) glTexCoord2f(0.0, 1.0) glVertex3f(25.0,25.0,25.0) glEnd() glPopMatrix() # Disable lighting, we'll just draw the shadow as black glDisable(GL_LIGHTING) glDisable(GL_TEXTURE_2D) glPushMatrix() pPlane = m3dGetPlaneEquation(ground[0], ground[1], ground[2]) mCubeTransform = m3dMakePlanarShadowMatrix(pPlane, vLightPos) glMultMatrixf(mCubeTransform) glTranslatef(-10.0, 0.0, 10.0) # Set drawing color to Black glColor3f(0.0, 0.0, 0.0) glutSolidCube(50.0) glPopMatrix()
def __init__(self, *args, **kwargs): global groundList, sphereList, torusList window.Window.__init__(self, *args, **kwargs) # pyglet reverses y axis vPoints = (M3DVector3f * 3)((0.0, -0.4, 0.0), (10.0, -0.4, 0.0), (5.0,-0.4, -5.0) ) # Grayish background glClearColor(fLowLight[0], fLowLight[1], fLowLight[2], fLowLight[3]) # Clear stencil buffer with zero, increment by one whenever anybody # draws into it. When stencil function is enabled, only write where # stencil value is zero. This prevents the transparent shadow from drawing # over itself glStencilOp(GL_INCR, GL_INCR, GL_INCR) glClearStencil(0) glStencilFunc(GL_EQUAL, 0x0, 0x01) # Cull backs of polygons glCullFace(GL_BACK) glFrontFace(GL_CCW) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) glEnable(GL_MULTISAMPLE_ARB) # Setup light parameters glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fNoLight) glLightfv(GL_LIGHT0, GL_AMBIENT, fLowLight) glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight) glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) # TODO: this doesn't seem to be enough to make this work on my computer? glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR) # Calculate shadow matrix pPlane = m3dGetPlaneEquation(vPoints[0], vPoints[1] , vPoints[2]) mShadowMatrix = m3dMakePlanarShadowMatrix(pPlane, fLightPos) # Mostly use material tracking glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight) glMateriali(GL_FRONT, GL_SHININESS, 128) # Randomly place sphere inhabitants for sphere in spheres: # Pick a random location between -20 and 20 at .1 increments sphere.setOrigin(float(randint(-200, 200)) * 0.1, 0.0, float(randint(-200, 200)) * 0.1) # Set up texture maps glEnable(GL_TEXTURE_2D) glGenTextures(NUM_TEXTURES, textureObjects) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) for iLoop in range(0, NUM_TEXTURES): glBindTexture(GL_TEXTURE_2D, textureObjects[iLoop]) # Load this texture map img = pyglet.image.load(szTextureFiles[iLoop]) gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, img.width, img.height, GL_RGB, GL_UNSIGNED_BYTE, img.get_data('RGB', img.pitch)) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) # Create display lists firstlist = glGenLists(3) groundList = GLuint(firstlist) sphereList = GLuint(firstlist + 1) torusList = GLuint(firstlist + 2) print firstlist # Create sphere display list glNewList(sphereList, GL_COMPILE) glutSolidSphere(0.1, 40, 20) glEndList() # Create torus display list glNewList(torusList, GL_COMPILE) gltDrawTorus(0.35, 0.15, 61, 37) glEndList() # Create the ground display list glNewList(groundList, GL_COMPILE) DrawGround() glEndList()