def __init__(self, w, h, title='Pyglet App'): super(Window, self).__init__(w, h, title) # Grayish background glClearColor(*self.fLowLight) # 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, self.fNoLight) glLightfv(GL_LIGHT0, GL_AMBIENT, self.fLowLight) glLightfv(GL_LIGHT0, GL_DIFFUSE, self.fBrightLight) glLightfv(GL_LIGHT0, GL_SPECULAR, self.fBrightLight) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) # Calculate shadow matrix vPoints = [ [0.0, -0.4, 0.0], [10.0, -0.4, 0.0], [5.0, -0.4, -5.0], ] # Get the plane equation from three points on the ground vPlaneEquation = M3DVector4f() m3dGetPlaneEquation(vPlaneEquation, vPoints[0], vPoints[1], vPoints[2]) # Calculate projection matrix to draw shadow on the ground m3dMakePlanarShadowMatrix(self.mShadowMatrix, vPlaneEquation, self.fLightPos) self.mShadowMatrix = gl_vec(GLfloat, self.mShadowMatrix) # Mostly use material tracking glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glMateriali(GL_FRONT, GL_SHININESS, 128) # Randomly place the sphere inhabitants for iSphere in range(self.NUM_SPHERES): # Pick a random location between -20 and 20 at .1 increments s = GLFrame() x = rand() * 40 - 20 z = rand() * 40 - 20 s.SetOrigin(x, 0.0, z) self.spheres[iSphere] = s glEnable(GL_MULTISAMPLE) # This is actually on by default self._make_display_list('small sphere', self._draw_small_sphere) self._make_display_list('big sphere', self._draw_big_sphere) self._make_display_list('torus', self._draw_torus) self._make_display_list('ground', self._draw_ground) pyglet.clock.schedule_interval(self._update, 1.0 / 60.0) pyglet.clock.schedule_interval(self.fps, 2.0)
def __init__(self, w, h, title='Pyglet App'): super(Window, self).__init__(w, h, title) glEnable(GL_MULTISAMPLE_ARB) # Grayish background glClearColor(*self.fLowLight) # 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) # Turn Fog on glFogfv(GL_FOG_COLOR, self.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, self.fNoLight); glLightfv(GL_LIGHT0, GL_AMBIENT, self.fLowLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, self.fBrightLight); glLightfv(GL_LIGHT0, GL_SPECULAR, self.fBrightLight); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); # Calculate shadow matrix vPoints = [ [0.0, -0.4, 0.0], [10.0, -0.4, 0.0], [5.0, -0.4, -5.0], ] # Get the plane equation from three points on the ground vPlaneEquation = M3DVector4f() m3dGetPlaneEquation(vPlaneEquation, vPoints[0], vPoints[1], vPoints[2]); # Calculate projection matrix to draw shadow on the ground m3dMakePlanarShadowMatrix(self.mShadowMatrix, vPlaneEquation, self.fLightPos); self.mShadowMatrix = gl_vec(GLfloat, self.mShadowMatrix) # Mostly use material tracking glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glMateriali(GL_FRONT, GL_SHININESS, 128); # Randomly place the sphere inhabitants for iSphere in range(self.NUM_SPHERES): # Pick a random location between -20 and 20 at .1 increments s = GLFrame() x = rand() * 40 - 20 z = rand() * 40 - 20 s.SetOrigin(x, 0.0, z) self.spheres[iSphere] = s self._make_display_list('small sphere', self._draw_small_sphere) self._make_display_list('big sphere', self._draw_big_sphere) self._make_display_list('torus', self._draw_torus) self._make_display_list('ground', self._draw_ground) pyglet.clock.schedule_interval(self._update, 1.0/60.0) pyglet.clock.schedule_interval(self.fps, 2.0)
def __init__(self, w, h, title='Pyglet App'): super(Window, self).__init__(w, h, title) # Grayish background glClearColor(*self.fLowLight) # 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, self.fNoLight) glLightfv(GL_LIGHT0, GL_AMBIENT, self.fLowLight) glLightfv(GL_LIGHT0, GL_DIFFUSE, self.fBrightLight) glLightfv(GL_LIGHT0, GL_SPECULAR, self.fBrightLight) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) # Calculate shadow matrix vPoints = [ [0.0, -0.4, 0.0], [10.0, -0.4, 0.0], [5.0, -0.4, -5.0], ] pPlane = M3DVector4f() m3dGetPlaneEquation(pPlane, vPoints[0], vPoints[1], vPoints[2]) m3dMakePlanarShadowMatrix(self.mShadowMatrix, pPlane, self.fLightPos) self.mShadowMatrix = gl_vec(GLfloat, self.mShadowMatrix) # Mostly use material tracking glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) glMaterialfv(GL_FRONT, GL_SPECULAR, self.fBrightLight) glMateriali(GL_FRONT, GL_SHININESS, 128) # Randomly place the sphere inhabitants for iSphere in range(self.NUM_SPHERES): # Pick a random location between -20 and 20 at .1 increments s = GLFrame() x = rand() * 40 - 20 z = rand() * 40 - 20 s.SetOrigin(x, 0.0, z) self.spheres[iSphere] = s # Set up texture maps glEnable(GL_TEXTURE_2D) for name in self.szTextureFiles: image = pyglet.image.load(name) texid = image.get_mipmapped_texture().id self.images.append(image) self.textureObjects.append(texid) # Set up display lists for faster rendering self._make_display_list('ground', self._draw_ground) self._make_display_list('torus', self._draw_torus) self._make_display_list('big sphere', self._draw_big_sphere) self._make_display_list('small sphere', self._draw_small_sphere) pyglet.clock.schedule_interval(self._update, 1.0 / 60.0) pyglet.clock.schedule_interval(self.fps, 2.0)