def draw(self): # Prepare our texture glDisable(GL_DEPTH_TEST) glDisable(GL_CULL_FACE) GLExtension.disableMultitex() glEnable(GL_TEXTURE_2D) glDisable(GL_LIGHTING) glDisable(GL_BLEND) glColor3f(1,1,1) self.factory.texture.bind() # Rotate the texture matrix glMatrixMode(GL_TEXTURE) glLoadIdentity() glRotatef(self.angle, 0,0,1) glTranslatef(-self.factory.rotationDistance, -self.factory.rotationDistance, 0) glMatrixMode(GL_MODELVIEW) drawTexRect(self.viewport.size, (self.factory.scale, self.factory.scale)) # Clean up glMatrixMode(GL_TEXTURE) glLoadIdentity() glMatrixMode(GL_MODELVIEW) glDisable(GL_TEXTURE_2D)
def render(self): glEnable(GL_BLEND) glDisable(GL_LIGHTING) glDisable(GL_CULL_FACE) glDisable(GL_COLOR_MATERIAL) glDisable(GL_DEPTH_TEST) GLExtension.disableMultitex() glDisable(GL_TEXTURE_2D) glLoadIdentity() size = self.viewport.size def square(): # Set the square inside our viewport by one # pixel so the antialiased lines won't be chopped in half. glVertex2f(1,1) glVertex2f(size[0]-1, 1) glVertex2f(size[0]-1, size[1]-1) glVertex2f(1, size[1]-1) # Creamy translucent filling glColor4f(0,0,0,0.3) glBegin(GL_POLYGON) square() glEnd() # Bright border glColor4f(1,1,1,1) glBegin(GL_LINE_LOOP) square() glEnd()
def init(self): # Test for OpenGL extensions we can use GLExtension.test() self.nearClip = 0.1 self.farClip = 2500.0 self.fov = 45.0 # Set up some common OpenGL defaults glClearDepth(1.0) glDepthFunc(GL_LESS) glShadeModel(GL_SMOOTH) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) # Set up the Mode object that handles viewport-wide per-frame modes. # By default we use ClearedMode. self.mode = ClearedMode()
def draw(self, size=None, color=(1,1,1,1)): """Draw the noise, optionally scaled to the given size and modulated by the given color""" if not size: size = self.frames[0].size GLExtension.disableMultitex() glDisable(GL_TEXTURE_2D) glDisable(GL_LIGHTING) glDisable(GL_DEPTH_TEST) glDisable(GL_CULL_FACE) glEnable(GL_BLEND) # To smoothly blend between two frames, we will need to know which two frames # we're blending between, and the amount of fading between them. The fade value # will be 0 for 100% frame1, and 1 for 100% frame2. frameNum = int(self.time / self.frameDuration) frame1 = self.frames[frameNum] frame2 = self.frames[frameNum+1] fade = (self.time % self.frameDuration) / self.frameDuration # To properly blend between the existing data in the color buffer and the # two frames, we need to do the blend operation in three passes. # 1. Multiply the color buffer by (1-alpha) glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA) glColor4f(1,1,1,color[3]) drawTexRect(size) # 2. Multiply the first frame by (alpha * (1-fade)) and add it to the color buffer glEnable(GL_TEXTURE_2D) glBlendFunc(GL_SRC_ALPHA, GL_ONE) glColor4f(color[0], color[1], color[2], color[3] * (1-fade)) frame1.bind() drawTexRect(size) # 3. Multiply the second frame by (alpha * fade) and add it to the color buffer glColor4f(color[0], color[1], color[2], color[3] * fade) frame2.bind() drawTexRect(size) glDisable(GL_BLEND) glDisable(GL_TEXTURE_2D) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
def render(self): self.updateFollowing() rstate = Drawable.RenderState(self) glEnable(GL_BLEND) glDisable(GL_LIGHTING) glDisable(GL_CULL_FACE) glDisable(GL_COLOR_MATERIAL) glDisable(GL_DEPTH_TEST) GLExtension.disableMultitex() glDisable(GL_TEXTURE_2D) glEnable(GL_LINE_SMOOTH) size = self.viewport.size glPushMatrix() glScalef(size[0], size[1], 1) glTranslatef(0.5, 0.5, 0) glScalef( float(self.zoom) / self.game.world.size[0], -float(self.zoom) / self.game.world.size[1], 1) glRotatef(self.angle, 0,0,1) glTranslatef(-self.center[0], -self.center[1], 0) self.scene.render(rstate, self.center[2]) self.renderPlayers(rstate) glPopMatrix()