def _drawBox(self): #Draw box gl2D.start2D() GraphicsCard.disable('texture_2d', 'depth_test', 'alpha_test', 'cull_face') GraphicsCard.enable('blend') self.bounds.draw( *self.backgroundColor) gl2D.end2D()
def drawScreen( self ): """Draw the screen""" GraphicsCard.resetPolygonCount() GraphicsCard.enable('texture_2d', 'blend', 'cull_face') GraphicsCard.setBlendFunction('src_alpha', 'one_minus_src_alpha' ) GraphicsCard.setFrontFace('ccw') GraphicsCard.loadIdentity() GraphicsCard.multMatrix( self.world.camera.getViewMatrix().toList() ) glLightfv( GL_LIGHT0, GL_POSITION, [0, 1, 0, 0] ) GraphicsCard.clearDepth(1.0) GraphicsCard.clear() #Draw the world self.world.draw() TextureManager.DisableStage( 1 ) TextureManager.DisableStage( 2 ) if Settings.UseShaders: Shader.DisableShaders() #self.font.draw( 0, 0, "FPS: " + str( self.fps ) ) DebugDisplay.update("FPS", self.fps, delay=0.3333 ) DebugDisplay.update("yaw", radianToDegree( self.world.camera.yaw) ) DebugDisplay.update("pitch", radianToDegree( self.world.camera.pitch )) DebugDisplay.update("polygons_drawn", GraphicsCard.polygonsDrawn() ) if self.world.playerEnt: DebugDisplay.update("onGround", self.world.playerEnt.onGround ) DebugDisplay.update("groundNormal", self.world.playerEnt.groundNormal ) GraphicsCard.loadIdentity() if self.consoleVisible: self.console.draw() gl2D.start2D() if Settings.DrawDebugInfo: GraphicsCard.setColorRGBA(1, 1, 1, 1) self.font.draw(0, 0, str(DebugDisplay.globalState)) self.world.scene.drawDebugInfo(self.font) else: GraphicsCard.setColorRGBA(1, 1, 1, 1) pygame.display.set_caption("FPS: " + str(DebugDisplay.get("FPS"))) #self.bigfont.draw(0, 0, "Ninjas Killed: %s" % (self.world.ninjasKilled) ) #self.bigfont.draw(0, 30, "Pirates Killed: %s" % (self.world.piratesKilled) ) #self.bigfont.draw(0, 60, "Treasures Stolen: %s" % (self.world.treasuresTaken) ) #DebugDisplay.globalState.draw( self.font ) gl2D.end2D() #put stuff on the screen pygame.display.flip() err = graphext.GetGLError() while err != GL_NO_ERROR: print err print graphext.GLErrorString( err)
def drawScreen(self): """Draw the screen""" GraphicsCard.resetPolygonCount() GraphicsCard.enable('texture_2d', 'blend', 'cull_face') GraphicsCard.setBlendFunction('src_alpha', 'one_minus_src_alpha') GraphicsCard.setFrontFace('ccw') GraphicsCard.loadIdentity() GraphicsCard.multMatrix(self.world.camera.getViewMatrix().toList()) glLightfv(GL_LIGHT0, GL_POSITION, [0, 1, 0, 0]) GraphicsCard.clearDepth(1.0) GraphicsCard.clear() #Draw the world self.world.draw() TextureManager.DisableStage(1) TextureManager.DisableStage(2) if Settings.UseShaders: Shader.DisableShaders() #self.font.draw( 0, 0, "FPS: " + str( self.fps ) ) DebugDisplay.update("FPS", self.fps, delay=0.3333) DebugDisplay.update("yaw", radianToDegree(self.world.camera.yaw)) DebugDisplay.update("pitch", radianToDegree(self.world.camera.pitch)) DebugDisplay.update("polygons_drawn", GraphicsCard.polygonsDrawn()) if self.world.playerEnt: DebugDisplay.update("onGround", self.world.playerEnt.onGround) DebugDisplay.update("groundNormal", self.world.playerEnt.groundNormal) GraphicsCard.loadIdentity() if self.consoleVisible: self.console.draw() gl2D.start2D() if Settings.DrawDebugInfo: GraphicsCard.setColorRGBA(1, 1, 1, 1) self.font.draw(0, 0, str(DebugDisplay.globalState)) self.world.scene.drawDebugInfo(self.font) else: GraphicsCard.setColorRGBA(1, 1, 1, 1) pygame.display.set_caption("FPS: " + str(DebugDisplay.get("FPS"))) #self.bigfont.draw(0, 0, "Ninjas Killed: %s" % (self.world.ninjasKilled) ) #self.bigfont.draw(0, 30, "Pirates Killed: %s" % (self.world.piratesKilled) ) #self.bigfont.draw(0, 60, "Treasures Stolen: %s" % (self.world.treasuresTaken) ) #DebugDisplay.globalState.draw( self.font ) gl2D.end2D() #put stuff on the screen pygame.display.flip() err = graphext.GetGLError() while err != GL_NO_ERROR: print err print graphext.GLErrorString(err)
def drawPrim(self, x, y, text, max_width=None ): screen_height = gl2D.screenSize()[1] gl2D.start2D() cx = x cy = y last_character = 0 current_page = 0 self.texture_pages[current_page].bind() texwidth = self.texture_pages[current_page].width texheight = self.texture_pages[current_page].height glPushMatrix() glTranslatef(cx, screen_height-cy, 0) #glBegin(GL_QUADS) for c in text: if ord(c) == 10: cy += self.size glTranslatef( -(cx-x), -self.size, 0) cx = x continue ch = self.chars[ord(c)] kerning_key = (last_character,ch.id) if kerning_key in self.kerning: k_amt = self.kerning[ kerning_key ] cx += int(k_amt) glTranslatef(cx, 0, 0) if ch.page != current_page: current_page = ch.page self.texture_pages[current_page].bind() texwidth = self.texture_pages[current_page].width texheight = self.texture_pages[current_page].height #gl2D.drawSubTexture2D( self.texture_pages[current_page], cx + ch.xoffset, cy + ch.yoffset, ch.x, ch.y, ch.width, ch.height ) #drawQuad( texwidth, texheight, cx+ch.xoffset, cy+ch.yoffset, ch.x, ch.y, ch.width, ch.height ) #glPushMatrix() #glTranslatef(cx, screen_height-cy, 0) if max_width and (cx-x)+ch.xadvance > max_width: break ch.draw() #glPopMatrix() cx += ch.xadvance glTranslatef( ch.xadvance, 0, 0 ) last_character = ord(c) #glEnd() glPopMatrix() gl2D.end2D() return (cx, cy)
def drawPrim(self, x, y, text, max_width=None): screen_height = gl2D.screenSize()[1] gl2D.start2D() cx = x cy = y last_character = 0 current_page = 0 self.texture_pages[current_page].bind() texwidth = self.texture_pages[current_page].width texheight = self.texture_pages[current_page].height glPushMatrix() glTranslatef(cx, screen_height - cy, 0) #glBegin(GL_QUADS) for c in text: if ord(c) == 10: cy += self.size glTranslatef(-(cx - x), -self.size, 0) cx = x continue ch = self.chars[ord(c)] kerning_key = (last_character, ch.id) if kerning_key in self.kerning: k_amt = self.kerning[kerning_key] cx += int(k_amt) glTranslatef(cx, 0, 0) if ch.page != current_page: current_page = ch.page self.texture_pages[current_page].bind() texwidth = self.texture_pages[current_page].width texheight = self.texture_pages[current_page].height #gl2D.drawSubTexture2D( self.texture_pages[current_page], cx + ch.xoffset, cy + ch.yoffset, ch.x, ch.y, ch.width, ch.height ) #drawQuad( texwidth, texheight, cx+ch.xoffset, cy+ch.yoffset, ch.x, ch.y, ch.width, ch.height ) #glPushMatrix() #glTranslatef(cx, screen_height-cy, 0) if max_width and (cx - x) + ch.xadvance > max_width: break ch.draw() #glPopMatrix() cx += ch.xadvance glTranslatef(ch.xadvance, 0, 0) last_character = ord(c) #glEnd() glPopMatrix() gl2D.end2D() return (cx, cy)
def draw(self, x, y, text, static=False, max_width=None): """Draw the font""" glEnable(GL_TEXTURE_2D) glEnable( GL_ALPHA_TEST) glAlphaFunc(GL_GREATER,0.5) glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) glDisable(GL_CULL_FACE) #glDisable(GL_BLEND) if not static: return self.drawPrim( x, y, text, max_width ) else: try: dl, w, h = self.optimizedStrings[text] except: dl, w, h = self.makeDisplayListforString(text) gl2D.start2D() glPushMatrix() glLoadIdentity() glTranslatef( x, y, 0 ) dl() glPopMatrix() gl2D.end2D() return w, h
def draw(self, x, y, text, static=False, max_width=None): """Draw the font""" glEnable(GL_TEXTURE_2D) glEnable(GL_ALPHA_TEST) glAlphaFunc(GL_GREATER, 0.5) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glDisable(GL_CULL_FACE) #glDisable(GL_BLEND) if not static: return self.drawPrim(x, y, text, max_width) else: try: dl, w, h = self.optimizedStrings[text] except: dl, w, h = self.makeDisplayListforString(text) gl2D.start2D() glPushMatrix() glLoadIdentity() glTranslatef(x, y, 0) dl() glPopMatrix() gl2D.end2D() return w, h
def load(self): self.keyDown = {} self.fps = 0 self.right_btn = False #initialize the screen/window self.size = self.width, self.height = Settings.Resolution self.fullscreen = Settings.Fullscreen self.resetVideoMode() #init network variable thingy self.network = None #create console self.console = Console.Console( Graphics.Rectangle( 20, 20, self.width-20, self.height-20) ) self.console.setAsStdOut() self.console.onInput = self.onConsoleInput #initialize some basic opengl states GraphicsCard.enable( 'depth_test') GraphicsCard.setDepthFunc('less') GraphicsCard.setShadeModel( 'smooth' ) GraphicsCard.setScreenProjection( float(self.width/self.height), 0.1, 5000.0 ) self.font = Font.TextureFont( '../base/fonts/tahoma.fnt' ) self.bigfont = Font.TextureFont( '../base/fonts/tahoma_20.fnt' ) FontManager.GetFont( Settings.ConsoleFont ) loadscreen = TextureManager.GetTexture( '../base/art/ui/facehatlogo.png' ) #Draw loading screen GraphicsCard.clearDepth(1.0) GraphicsCard.clearColor( (1, 1, 1, 1) ) GraphicsCard.clear() #glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) GraphicsCard.setBlendFunction( 'src_alpha', 'one_minus_src_alpha' ) GraphicsCard.enable( 'blend', 'texture_2d') gl2D.start2D() gl2D.drawTexture2D( loadscreen, self.width/2-256, self.height/2-256, 512, 512 ) self.bigfont.draw(self.width/2, self.height/2-280, "Loading..." ) gl2D.end2D() pygame.display.flip() #hide/show cursor if Settings.GrabMouse: pygame.mouse.set_visible(False) pygame.event.set_grab(True) else: pygame.mouse.set_visible(True) pygame.event.set_grab(False) #Initialize OpenGL extensions GraphicsCard.initExtensions() #check for OpenGL 2.0 if Settings.UseShaders and GraphicsCard.hasShaders(): print "Shader Support Present" Settings.UseShaders = True else: print "Warning: No shader support, or shaders disabled" Settings.UseShaders = False print "Max Anisotropy:", GraphicsCard.getMaxAnisotropy() ###load the map if Settings.SinglePlayer: self.world = World.World( Settings.DefaultMod, Settings.DefaultMap, is_server=True, graphics_enabled=True ) else: self.world = World.World( Settings.DefaultMod, Settings.DefaultMap, is_server=False, graphics_enabled=True ) self.world.initGraphics() self.lastjump = time_in_seconds() #setup lighting n = vec3(0, 1, 0 ) glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0] ) glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, [0.9, 0.9, 0.9, 1.0] ) glLightfv( GL_LIGHT0, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0 ] ) glLightfv( GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0 ] ) glLightfv( GL_LIGHT0, GL_POSITION, [n.x, n.y, n.z, 0] ) GraphicsCard.clearColor((0.0, 0.0, 1.0, 0.0)) GraphicsCard.enable('light0')
def load(self): self.keyDown = {} self.fps = 0 self.right_btn = False #initialize the screen/window self.size = self.width, self.height = Settings.Resolution self.fullscreen = Settings.Fullscreen self.resetVideoMode() #init network variable thingy self.network = None #create console self.console = Console.Console( Graphics.Rectangle(20, 20, self.width - 20, self.height - 20)) self.console.setAsStdOut() self.console.onInput = self.onConsoleInput #initialize some basic opengl states GraphicsCard.enable('depth_test') GraphicsCard.setDepthFunc('less') GraphicsCard.setShadeModel('smooth') GraphicsCard.setScreenProjection(float(self.width / self.height), 0.1, 5000.0) self.font = Font.TextureFont('../base/fonts/tahoma.fnt') self.bigfont = Font.TextureFont('../base/fonts/tahoma_20.fnt') FontManager.GetFont(Settings.ConsoleFont) loadscreen = TextureManager.GetTexture( '../base/art/ui/facehatlogo.png') #Draw loading screen GraphicsCard.clearDepth(1.0) GraphicsCard.clearColor((1, 1, 1, 1)) GraphicsCard.clear() #glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) GraphicsCard.setBlendFunction('src_alpha', 'one_minus_src_alpha') GraphicsCard.enable('blend', 'texture_2d') gl2D.start2D() gl2D.drawTexture2D(loadscreen, self.width / 2 - 256, self.height / 2 - 256, 512, 512) self.bigfont.draw(self.width / 2, self.height / 2 - 280, "Loading...") gl2D.end2D() pygame.display.flip() #hide/show cursor if Settings.GrabMouse: pygame.mouse.set_visible(False) pygame.event.set_grab(True) else: pygame.mouse.set_visible(True) pygame.event.set_grab(False) #Initialize OpenGL extensions GraphicsCard.initExtensions() #check for OpenGL 2.0 if Settings.UseShaders and GraphicsCard.hasShaders(): print "Shader Support Present" Settings.UseShaders = True else: print "Warning: No shader support, or shaders disabled" Settings.UseShaders = False print "Max Anisotropy:", GraphicsCard.getMaxAnisotropy() ###load the map if Settings.SinglePlayer: self.world = World.World(Settings.DefaultMod, Settings.DefaultMap, is_server=True, graphics_enabled=True) else: self.world = World.World(Settings.DefaultMod, Settings.DefaultMap, is_server=False, graphics_enabled=True) self.world.initGraphics() self.lastjump = time_in_seconds() #setup lighting n = vec3(0, 1, 0) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0]) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [0.9, 0.9, 0.9, 1.0]) glLightfv(GL_LIGHT0, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0]) glLightfv(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0]) glLightfv(GL_LIGHT0, GL_POSITION, [n.x, n.y, n.z, 0]) GraphicsCard.clearColor((0.0, 0.0, 1.0, 0.0)) GraphicsCard.enable('light0')
def end2D(): gl2D.end2D()