Ejemplo n.º 1
0
 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()
Ejemplo n.º 2
0
 def draw(self):
     glFrontFace( GL_CW )
     if Settings.UseDisplayLists:
         if self.display_list is None: self.buildDisplayList()
         self.display_list()
     else:
         self.drawSimple()
     GraphicsCard.recordDraw(self.polygonCount)
Ejemplo n.º 3
0
 def draw(self):
     glFrontFace(GL_CW)
     if Settings.UseDisplayLists:
         if self.display_list is None: self.buildDisplayList()
         self.display_list()
     else:
         self.drawSimple()
     GraphicsCard.recordDraw(self.polygonCount)
Ejemplo n.º 4
0
 def draw(self, mode=GL_TRIANGLES, count=None, offset=0):
     #glDrawElements( GL_TRIANGLES, 1, self.glTypeCode, 0 )
     if count == None:
         count = len(self.indices)
     glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, self.id)
     graphext.DrawElementsVB(mode, count, self.glTypeCode, 0)
     GraphicsCard.recordDraw(int(count / 3))
     glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0)
Ejemplo n.º 5
0
 def draw(self):
     GraphicsCard.enable('blend')
     GraphicsCard.setBlendFunction('src_alpha', 'one_minus_src_alpha')
     GraphicsCard.disable('lighting', 'texture_2d')
     alpha = max( float(self.timeleft / 2.0), 0 )
     GraphicsCard.setColorRGBA( alpha/2.0, 0, 0, alpha )
     Graphics.drawSphere( self.location, 4, 8, 4 )
     GraphicsCard.enable('texture_2d')
Ejemplo n.º 6
0
 def setUnderwaterState(self):
     a,r,g,b = 1, 0.1, 0.4, 0.7#self.fogColor
     GraphicsCard.clearColor( (r, g, b, a) )
     glFogi( GL_FOG_MODE, GL_LINEAR )
     glFogfv( GL_FOG_COLOR, [r,g,b,a] )
     glFogf( GL_FOG_DENSITY, 1.0 )
     glHint( GL_FOG_HINT, GL_DONT_CARE )
     glFogf( GL_FOG_START, 10)
     glFogf( GL_FOG_END,  600)
     glEnable(GL_FOG)
     GraphicsCard.setScreenProjection( float(GraphicsCard.width/GraphicsCard.height), 0.1, 600)
Ejemplo n.º 7
0
 def setUnderwaterState(self):
     a, r, g, b = 1, 0.1, 0.4, 0.7  #self.fogColor
     GraphicsCard.clearColor((r, g, b, a))
     glFogi(GL_FOG_MODE, GL_LINEAR)
     glFogfv(GL_FOG_COLOR, [r, g, b, a])
     glFogf(GL_FOG_DENSITY, 1.0)
     glHint(GL_FOG_HINT, GL_DONT_CARE)
     glFogf(GL_FOG_START, 10)
     glFogf(GL_FOG_END, 600)
     glEnable(GL_FOG)
     GraphicsCard.setScreenProjection(
         float(GraphicsCard.width / GraphicsCard.height), 0.1, 600)
Ejemplo n.º 8
0
    def draw( self ):
        """Draw the terrain"""
        #if self.displayList is None: self.initGraphics()

        GraphicsCard.recordDraw( ((self.size-1)*(self.size-1)*2) * len(self.material.layers) )
        #if Settings.UseShaders:

        self.displayList()

        if Settings.DrawGrass:
            #self.grassPatch.draw()
            self.grassDisplayList()
Ejemplo n.º 9
0
    def draw(self):
        """Draw the terrain"""
        #if self.displayList is None: self.initGraphics()

        GraphicsCard.recordDraw(((self.size - 1) * (self.size - 1) * 2) *
                                len(self.material.layers))
        #if Settings.UseShaders:

        self.displayList()

        if Settings.DrawGrass:
            #self.grassPatch.draw()
            self.grassDisplayList()
Ejemplo n.º 10
0
    def setState(self):
        a,r,g,b = self.fogColor
        GraphicsCard.clearColor((r, g, b, a))
        glFogi( GL_FOG_MODE, GL_LINEAR )
        glFogfv( GL_FOG_COLOR, [r,g,b,a] )
        glFogf( GL_FOG_DENSITY, 0.35 )
        glHint( GL_FOG_HINT, GL_DONT_CARE )
        glFogf( GL_FOG_START, float(self.fogStart) )
        glFogf( GL_FOG_END,  float(self.fogEnd) )
        glEnable(GL_FOG)

        #set the projection matrix
        #glMatrixMode(GL_PROJECTION)
        #glLoadIdentity()
        #gluPerspective(60.0, float(Graphics.width)/float(Graphics.height), 0.1, self.viewDistance)
        #glMatrixMode(GL_MODELVIEW)
        GraphicsCard.setScreenProjection( float(GraphicsCard.width/GraphicsCard.height), 0.1, self.viewDistance )
Ejemplo n.º 11
0
    def setState(self):
        a, r, g, b = self.fogColor
        GraphicsCard.clearColor((r, g, b, a))
        glFogi(GL_FOG_MODE, GL_LINEAR)
        glFogfv(GL_FOG_COLOR, [r, g, b, a])
        glFogf(GL_FOG_DENSITY, 0.35)
        glHint(GL_FOG_HINT, GL_DONT_CARE)
        glFogf(GL_FOG_START, float(self.fogStart))
        glFogf(GL_FOG_END, float(self.fogEnd))
        glEnable(GL_FOG)

        #set the projection matrix
        #glMatrixMode(GL_PROJECTION)
        #glLoadIdentity()
        #gluPerspective(60.0, float(Graphics.width)/float(Graphics.height), 0.1, self.viewDistance)
        #glMatrixMode(GL_MODELVIEW)
        GraphicsCard.setScreenProjection(
            float(GraphicsCard.width / GraphicsCard.height), 0.1,
            self.viewDistance)
Ejemplo n.º 12
0
    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()
Ejemplo n.º 13
0
    def draw(self):
        if not self.font: self.font = FontManager.GetFont(Settings.ConsoleFont)
        self._drawBox()
        #draw prompt
        GraphicsCard.enableTexture(True)
        GraphicsCard.setColorRGBA(*self.foregroundColor)
        prompt = self.prompt + self.inputLine[:self.cursor] +  self.inputLine[self.cursor:]
        w, h = self.font.pixelSizeOf( self.prompt + self.inputLine[:self.cursor] )
        self.font.draw( self.bounds.left + w, self.bounds.bottom-12, "_")
        self.font.draw(self.bounds.left, self.bounds.bottom-12, prompt)

        #draw text lines
        lineheight = 10
        y = lineheight
        reversed_lines = self.lines[:]
        reversed_lines.reverse()
        max_lines_to_draw = min(int(self.bounds.height / lineheight)-1,
                                len(reversed_lines))
        for line in reversed_lines[:max_lines_to_draw]:
            self.font.draw(self.bounds.left, self.bounds.bottom-12-y, line, False, self.bounds.width)
            y += lineheight
Ejemplo n.º 14
0
 def draw( self ):
     if not self.meshFile: return
     mesh = MeshLoader.LoadMeshFromFile( self.meshFile )
     GraphicsCard.pushMatrix()
     self.setGraphicsTransform()
     GraphicsCard.translate( self.meshOffset.x, self.meshOffset.y, self.meshOffset.z)
     mesh.draw()
     GraphicsCard.popMatrix()
Ejemplo n.º 15
0
 def _drawSubMeshes(self, submesh, matrices ):
     submesh.startDraw()
     for matrix in matrices:
         GraphicsCard.pushMatrix()
         GraphicsCard.multMatrix( matrix.toList() )
         submesh.drawBuffer()
         GraphicsCard.popMatrix()
     submesh.endDraw()
Ejemplo n.º 16
0
 def _drawSubMeshes(self, submesh, matrices):
     submesh.startDraw()
     for matrix in matrices:
         GraphicsCard.pushMatrix()
         GraphicsCard.multMatrix(matrix.toList())
         submesh.drawBuffer()
         GraphicsCard.popMatrix()
     submesh.endDraw()
Ejemplo n.º 17
0
 def draw(self):
     if not self.meshFile: return
     mesh = MeshLoader.LoadMeshFromFile(self.meshFile)
     GraphicsCard.pushMatrix()
     self.setGraphicsTransform()
     GraphicsCard.translate(self.meshOffset.x, self.meshOffset.y,
                            self.meshOffset.z)
     mesh.draw()
     GraphicsCard.popMatrix()
Ejemplo n.º 18
0
def LoadTextureAdvanced( filename ):
    image = ImageLoader.load(filename)
    ix = image.size[0]
    iy = image.size[1]
    image = image.convert("RGBA")
    img_str = image.tostring("raw", "RGBA", 0, 1)

    # Create Texture
    texture = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, texture)   # 2d texture (x and y size)

    glPixelStorei(GL_UNPACK_ALIGNMENT,1)
    #glTexImage2D(GL_TEXTURE_2D, 0, 4, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, img_str)
    gluBuild2DMipmaps(GL_TEXTURE_2D, 4, ix, iy, GL_RGBA, GL_UNSIGNED_BYTE, img_str )
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
    GraphicsCard.setTextureAnisotropy( 8.0 )

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
    return texture, image
Ejemplo n.º 19
0
 def enable(lightnum):
     GraphicsCard.enable('light' + str(lightnum))
Ejemplo n.º 20
0
 def apply(self):
     GraphicsCard.loadIdentity()
     GraphicsCard.multMatrix( self.getViewMatrix().toList() )
Ejemplo n.º 21
0
 def setTransform( self ):
     GraphicsCard.multMatrix( self.body.GetMatrix() )
Ejemplo n.º 22
0
    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)
Ejemplo n.º 23
0
 def draw(self, camera):
     GraphicsCard.setFrontFace('CW')
     if Settings.UseVBO:
         self.drawWithVertexBuffers(camera)
     else:
         self.drawWithoutVB(camera)
Ejemplo n.º 24
0
    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')
Ejemplo n.º 25
0
 def setTransform(self):
     GraphicsCard.multMatrix(self.body.GetMatrix())
Ejemplo n.º 26
0
 def apply(self):
     GraphicsCard.loadIdentity()
     GraphicsCard.multMatrix(self.getViewMatrix().toList())
Ejemplo n.º 27
0
 def setGraphicsTransform(self):
     GraphicsCard.multMatrix(
         MathUtil.buildTransformMatrix(self.location, self.yaw, 0,
                                       0).toList())
Ejemplo n.º 28
0
 def setGraphicsTransform(self):
     if Settings.DebugTransforms:
         m = MathUtil.buildTransformMatrixQ(self.location, self.q4)
         GraphicsCard.multMatrix(m.toList())
     else:
         GraphicsCard.multMatrix(self.body.GetMatrix())
Ejemplo n.º 29
0
 def setTransform(self):
     GraphicsCard.multMatrix(self.getTransformMatrix().toList())
Ejemplo n.º 30
0
 def resetVideoMode(self):
     flags = pygame.OPENGL | pygame.DOUBLEBUF
     if self.fullscreen: flags |= pygame.FULLSCREEN
     self.screen = pygame.display.set_mode(self.size, flags )
     self.size = self.width, self.height = GraphicsCard.getScreenSize()
Ejemplo n.º 31
0
    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)
Ejemplo n.º 32
0
    def update(self):
        proj_m =GraphicsCard.getProjectionMatrix()
        #mat4(ListFunctions.flattenListOfLists( glGetDoublev( GL_PROJECTION_MATRIX ) ) )
        modl_m = self.camera.getViewMatrix()

        #proj = proj_m.transpose().toList()
        #modl = modl_m.toList()
        m = (proj_m.transpose() * modl_m).toList()

        """m = range(16)
        m[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
        m[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];
        m[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];
        m[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];

        m[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];
        m[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];
        m[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];
        m[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];

        m[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];
        m[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];
        m[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];
        m[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];

        m[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];
        m[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];
        m[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];
        m[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];"""

        # Create clipping planes
        self.planes = []

        #right
        p = Plane(0,0,0,0)
        p.a = m[3]-m[0]
        p.b = m[7]-m[4]
        p.c = m[11]-m[8]
        p.d = m[15]-m[12]
        self.planes.append( p )

        #left
        p = Plane(0,0,0,0)
        p.a = m[3]+m[0]
        p.b = m[7]+m[4]
        p.c = m[11]+m[8]
        p.d = m[15]+m[12]
        self.planes.append( p )

        #bottom
        p = Plane(0,0,0,0)
        p.a = m[3]+m[1]
        p.b = m[7]+m[5]
        p.c = m[11]+m[9]
        p.d = m[15]+m[13]
        self.planes.append( p )

        #top
        p = Plane(0,0,0,0)
        p.a = m[3]-m[1]
        p.b = m[7]-m[5]
        p.c = m[11]-m[9]
        p.d = m[15]-m[13]
        self.planes.append( p )

        #near
        p = Plane(0,0,0,0)
        p.a = m[3]+m[2]
        p.b = m[7]+m[6]
        p.c = m[11]+m[10]
        p.d = m[15]+m[14]
        #self.planes.append( p )

        #far
        p = Plane(0,0,0,0)
        p.a = m[3]-m[2]
        p.b = m[7]-m[6]
        p.c = m[11]-m[10]
        p.d = m[15]-m[14]
        #self.planes.append( p )

        #Normalize the planes
        #print "-----"
        for p in self.planes:
            p.normalize()
Ejemplo n.º 33
0
 def enable(lightnum):
     GraphicsCard.enable('light'+str(lightnum))
Ejemplo n.º 34
0
 def resetVideoMode(self):
     flags = pygame.OPENGL | pygame.DOUBLEBUF
     if self.fullscreen: flags |= pygame.FULLSCREEN
     self.screen = pygame.display.set_mode(self.size, flags)
     self.size = self.width, self.height = GraphicsCard.getScreenSize()
Ejemplo n.º 35
0
    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')
Ejemplo n.º 36
0
    def draw(self):
        if not self.isCameraBelowWater():
            self.atmosphere.draw(self.camera)
        self.setFog()
        GraphicsCard.disable( 'alpha_test')
        GraphicsCard.enable( 'blend' )
        GraphicsCard.setFrontFace( 'cw' )
        if Settings.DrawTerrain: self.terrain.draw()
        TextureManager.DisableStage( 1 )
        TextureManager.DisableStage( 2 )
        GraphicsCard.setFrontFace( 'ccw' )
        GraphicsCard.setAlphaFunc('greater', 0.5)
        GraphicsCard.disable( 'blend')
        GraphicsCard.enable( 'alpha_test', 'lighting')
        if Settings.DrawStaticMeshes: self.scene.draw()
        for blotch in self.deathBlotches:
            blotch.draw()

        self.drawOcean()
        self.scene.drawAiInfo()
        GraphicsCard.disable('lighting', 'fog')
Ejemplo n.º 37
0
 def setGraphicsTransform( self ):
     if Settings.DebugTransforms:
         m = MathUtil.buildTransformMatrixQ( self.location, self.q4)
         GraphicsCard.multMatrix( m.toList() )
     else:
         GraphicsCard.multMatrix( self.body.GetMatrix() )
Ejemplo n.º 38
0
 def setTransform(self):
     GraphicsCard.multMatrix(self.getTransformMatrix().toList())
Ejemplo n.º 39
0
 def setGraphicsTransform(self):
     GraphicsCard.multMatrix(MathUtil.buildTransformMatrix(self.location, self.yaw, 0, 0).toList())
Ejemplo n.º 40
0
 def draw(self, camera):
     GraphicsCard.setFrontFace('CW')
     if Settings.UseVBO:
         self.drawWithVertexBuffers(camera)
     else:
         self.drawWithoutVB(camera)
Ejemplo n.º 41
0
 def drawWithoutBinding(self, mode=GL_TRIANGLES, count=None, offset=0):
     if count == None:
         count = len(self.indices)
     graphext.DrawElementsVB(mode, count, self.glTypeCode, 0)
     GraphicsCard.recordDraw(int(count / 3))