def __generate_shadows(self): """Generate shadow matrix for rotated model.""" glDisable(GL_CULL_FACE) glEnable(GL_POLYGON_OFFSET_FILL) glPolygonOffset(3, 0) self.__sh.change_shader(vertex=1, fragment=1) self.__prepare_shaders(self.__model_matrix, self.__light_matrix, True) self.__sh.bind_fbo() glClear(GL_DEPTH_BUFFER_BIT) glDrawElements(GL_TRIANGLES, View.__triangles.size, GL_UNSIGNED_SHORT, View.__triangles) glFinish() glBindFramebuffer(GL_FRAMEBUFFER, 0) self.__sh.clear()
def drawGround(self): GROUND_SIZE = 1000 glColor3f(0.9, 0.9, 0.9) glPushAttrib(GL_POLYGON_BIT) glEnable(GL_POLYGON_OFFSET_FILL) glPolygonOffset(2.0, 2.0) glDisable(GL_COLOR_MATERIAL) glPushMatrix() glTranslatef(0, 0, 0) glScalef(GROUND_SIZE, GROUND_SIZE, 1.0) glBegin(GL_QUADS) glVertex2d(1, 1) glVertex2d(1, -1) glVertex2d(-1, -1) glVertex2d(-1, 1) glEnd() glPopMatrix() glPopAttrib()
def startPatternedDrawing(highlight=False, select=False): """ Start drawing with a patterned style, if either highlight or select is passed as True, and the corresponding preference is set to select a patterned drawing style. This is common code for two different prefs keys, each of which has its own set of settings constants... Return value is True if one of the patterned styles is selected. """ (key, style, solid, pattern, edges, halos) = \ _decodePatternPrefs(highlight, select) if solid: # Nothing to do here for solid colors. return False # Set up stipple-patterned drawing styles. if pattern is not None: glEnable(GL_POLYGON_STIPPLE) glPolygonStipple(pattern) return True # Both polygon edges and halos are drawn in line-mode. if edges or halos: glPolygonMode(GL_FRONT, GL_LINE) glPolygonMode(GL_BACK, GL_LINE) if halos: # Draw wide, unshaded lines, offset a little bit away from the # viewer so that only the silhouette edges are visible. glDisable(GL_LIGHTING) glLineWidth(env.prefs[haloWidth_prefs_key]) glEnable(GL_POLYGON_OFFSET_LINE) glPolygonOffset(0.0, 5.e4) # Constant offset. pass pass return True
def startPatternedDrawing(highlight = False, select = False): """ Start drawing with a patterned style, if either highlight or select is passed as True, and the corresponding preference is set to select a patterned drawing style. This is common code for two different prefs keys, each of which has its own set of settings constants... Return value is True if one of the patterned styles is selected. """ (key, style, solid, pattern, edges, halos) = \ _decodePatternPrefs(highlight, select) if solid: # Nothing to do here for solid colors. return False # Set up stipple-patterned drawing styles. if pattern is not None: glEnable(GL_POLYGON_STIPPLE) glPolygonStipple(pattern) return True # Both polygon edges and halos are drawn in line-mode. if edges or halos: glPolygonMode(GL_FRONT, GL_LINE) glPolygonMode(GL_BACK, GL_LINE) if halos: # Draw wide, unshaded lines, offset a little bit away from the # viewer so that only the silhouette edges are visible. glDisable(GL_LIGHTING) glLineWidth(env.prefs[haloWidth_prefs_key]) glEnable(GL_POLYGON_OFFSET_LINE) glPolygonOffset(0.0, 5.e4) # Constant offset. pass pass return True
def endPatternedDrawing(highlight=False, select=False): """ End drawing with a patterned style, if either highlight or select is passed as True, and the corresponding preference is set to select a patterned drawing style. This is common code for two different prefs keys, each of which has its own set of settings constants... Return value is True if one of the patterned styles is selected. """ (key, style, solid, pattern, edges, halos) = \ _decodePatternPrefs(highlight, select) if solid: # Nothing to do here for solid colors. return False # End stipple-patterned drawing styles. if pattern is not None: glDisable(GL_POLYGON_STIPPLE) return True # End line-mode for polygon-edges or halos styles. if edges or halos: glPolygonMode(GL_FRONT, GL_FILL) glPolygonMode(GL_BACK, GL_FILL) if halos: # Back to normal lighting and treatment of lines and polygons. glEnable(GL_LIGHTING) glLineWidth(1.0) glDisable(GL_POLYGON_OFFSET_LINE) glPolygonOffset(0.0, 0.0) pass pass return True
def endPatternedDrawing(highlight = False, select = False): """ End drawing with a patterned style, if either highlight or select is passed as True, and the corresponding preference is set to select a patterned drawing style. This is common code for two different prefs keys, each of which has its own set of settings constants... Return value is True if one of the patterned styles is selected. """ (key, style, solid, pattern, edges, halos) = \ _decodePatternPrefs(highlight, select) if solid: # Nothing to do here for solid colors. return False # End stipple-patterned drawing styles. if pattern is not None: glDisable(GL_POLYGON_STIPPLE) return True # End line-mode for polygon-edges or halos styles. if edges or halos: glPolygonMode(GL_FRONT, GL_FILL) glPolygonMode(GL_BACK, GL_FILL) if halos: # Back to normal lighting and treatment of lines and polygons. glEnable(GL_LIGHTING) glLineWidth(1.0) glDisable(GL_POLYGON_OFFSET_LINE) glPolygonOffset(0.0, 0.0) pass pass return True
def processFrame(self, timePassedSecs): """ draws a scene """ # update the model view matrix self.sceneCamera.updateKeys() self.sceneCamera.update() # process queued GLObject events GLObject.signalsEmit() # enable some default scene states glEnable(GL_DEPTH_TEST) ######## SHADOW MAP RENDERING START ######## # offset the geometry slightly to prevent z-fighting # note that this introduces some light-leakage artifacts glEnable(GL_POLYGON_OFFSET_FILL) glPolygonOffset(1.1, 4096.0) # cull front faces for shadow rendering, # this moves z-fighting to backfaces. glCullFace(GL_FRONT) # enable depth rendering shader. # FIXME: support segment geometry shader! # geometry shader could change the shadow shape! self.depthShader.enable() map(_updateLightShadowMap, self.lights) glBindFramebuffer(GL_FRAMEBUFFER, 0) glDisable(GL_POLYGON_OFFSET_FILL) ######## SHADOW MAP RENDERING STOP ######## #### TODO: FOG: integrate FOG #### glEnable(GL_FOG) glFogi(GL_FOG_MODE, GL_EXP2) # approximate the atmosphere's filtering effect as a linear function sunDir = array([4.0, 4.0, 4.0, 0.0], float32) # TODO: FOG: what is the sun dir ? skyColor = array([0.8, sunDir[1] * 0.1 + 0.7, sunDir[1] * 0.4 + 0.5, 1.0], float32) glClearColor(*skyColor) glFogf(GL_FOG_DENSITY, 0.4) glFogf(GL_FOG_START, 16.0) glFogf(GL_FOG_END, self.farClip) glFogfv(GL_FOG_COLOR, skyColor) # fill projection matrix glMatrixMode(GL_PROJECTION) glLoadMatrixf(self.projectionMatrix) glMatrixMode(GL_MODELVIEW) # draw stuff in 3d projection lastCam = None glPushAttrib(GL_COLOR_BUFFER_BIT) for (fbo, draw, cam) in self.sceneFBOS: # render to fbo fbo.enable() if cam != lastCam: cam.enable() lastCam = cam draw() # disable render to texture FBO.disable() glPopAttrib() glViewport(0, 0, self.winSize[0], self.winSize[1]) #### TODO: FOG: integrate FOG #### glDisable(GL_FOG) # change to orthogonal projection glMatrixMode(GL_PROJECTION) glLoadMatrixf(self.orthoMatrix) glMatrixMode(GL_MODELVIEW) glLoadIdentity() # no depth test needed in orthogonal rendering glDisable(GL_DEPTH_TEST) # draw orthogonal to the screen self.orthogonalPass()