def __init__(self): #initialize the screen/window self.size = self.width, self.height = 1024, 768 self.screen = pygame.display.set_mode(self.size, pygame.OPENGL | pygame.DOUBLEBUF ) # | #pygame.FULLSCREEN ) glew.glewInit() #check for OpenGL 2.0 if glew.GLEW_ARB_vertex_shader and glew.GLEW_ARB_fragment_shader: print "Shader Support Present" #initialize some basic opengl states glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) #set the projection matrix GraphicsCard.setScreenProjection( float(self.width/self.height), 0.1, 5000.0 ) #glMatrixMode(GL_PROJECTION) #glLoadIdentity() #gluPerspective(60.0, float(self.width)/float(self.height), 0.1, 1000.0) #self.projection = glGetDoublev( GL_PROJECTION_MATRIX ) self.projection = GraphicsCard.screenProjection self.keyDown = {} self.font = Font.TextureFont( '../base/fonts/tahoma.fnt' ) self.fps = 0 #set camera self.camera = Camera.Freecam() self.camera.position = vec3( 0.0, 0.0, 1.5 ) self.camera.yaw = degreeToRadian( 0 ) self.camera.pitch = degreeToRadian( 0 ) self.right_btn = False #return to modelview glMatrixMode(GL_MODELVIEW) print "Base Init OK!" self.onInit()
def GetFont(filename): fnt = fonts.get(filename, None) if not fnt: fnt = Font.TextureFont(filename) fonts[filename] = fnt return fnt
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')