def view_update(self, width, height): glViewport(0, 0, width, height) # match openGL format self.persp_matrix = Matrix4.new_perspective(self.fov, width / float(height), self.clipnear, self.clipfar)
def SetProjectionInfo(self, width, height): self.zoomWidth = self.zoomWidth * width / self.width self.zoomHeight = self.zoomHeight * height / self.height self.width = width self.height = height if self.mode == self.MODE_PERSPECTIVE: self.projectionMatrix = Matrix4.new_perspective(math.pi / 2.0, max(width, 1.0) / max(height, 1.0), self.nearPlane, self.farPlane) else: self.SetOrthogonalInfo(self.zoomWidth, self.zoomHeight) self.projectionMatrix.transpose()
def draw(program,w,h): # Set the viewport. glViewport(0, 0, width, height) # Clear the color buffer. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glUseProgram(tri_program) loc = glGetUniformLocation(tri_program,"uPerspective") p = Matrix4.new_perspective(pi/6,4.0/3.0,0.1,10.0) glUniformMatrix4fv(loc, False, matToList(p)) loc = glGetUniformLocation(tri_program,"uLightDir") glUniform3f(loc,-1.0,0.4,0.7) loc = glGetUniformLocation(tri_program,"uFogDensity") glUniform1f(loc,fog_density) loc = glGetUniformLocation(tri_program,"uFogColor") glUniform4f(loc,0.3,0.3,0.35,1.0) draw_invader(1.0,-0.7,-4.0) draw_invader(0.1,0.2,-8.0) draw_invader(0.35,0.7,-9.0) # Use the text program object. glUseProgram(text_program) for slot in slots: slot.update() slot.draw_text_slot()
def update_projection(self): width, height = self.window.get_size() self.persp_matrix = Matrix4.new_perspective(self.fov, width / float(height), self.clipnear, self.clipfar)