Esempio n. 1
0
 def __init__(self, name, params):
     GLObject.__init__(self, params)
     
     # segment name
     self.segmentID = name
     
     self.shaderProgram = -1
     self.shader = None
     
     # texture for base coloring
     self.baseImage = None
     
     # segments needs material
     self.material = params.get('material')
     
     # get some default attributes
     self.isPlanar = self.getAttr("isPlane", False)
     if self.isPlanar:
         self.createReflectionHandler = createPlaneReflectionHandler
     else:
         pass
     self.reflectionHandler = None
     
     self.vertexPositionName = "vec4(vertexPosition, 1.0)"
     self.vertexNormalName = "vertexNormal"
     self.vertexColorName = "vertexColor"
     self.vertexUVName = "vertexUV"
Esempio n. 2
0
 def __init__(self, params):
     GLObject.__init__(self, params)
     self.matReflection = self.getAttr("matReflectionIntensity", 0.0)
     
     self.textures = []
     textures = params.get('textures', [])
     for tex in textures:
         self.addTexture(tex)
Esempio n. 3
0
 def __init__(self, position=None):
     GLObject.__init__(self, {})
     
     # the camera position
     self.position = position
     # model viw matrix of this camera
     self.modelViewMatrix = None
     print "REGISTER CAM MV ", Camera.CAMERA_MODELVIEW_SIGNAL
     # register the signal on this object
     self.signalRegister( Camera.CAMERA_MODELVIEW_SIGNAL )
Esempio n. 4
0
 def createDrawFunction(self):
     """
     generate the function used for drawing.
     """
     GLObject.createDrawFunction(self)
     if self.material!=None:
         # let material create the draw function and
         # include the material state setter/unsetter
         self.material.createDrawFunction()
         
         self.joinStaticStates(enable=self.material.enableStaticStates,
                               disable=self.material.disableStaticStates)
         self.joinDynamicStates(enable=self.material.enableDynamicStates,
                                disable=self.material.disableDynamicStates)
Esempio n. 5
0
 def __init__(self, params):
     # FIXME: lights may be on the same unit for long time,
     #            we do not have to set the states each frame then!
     self.name = params.get('name')
     GLObject.__init__(self, params)
     self.lightCutOff = self.getAttr("lightCutOff", 180.0)
     
     # signal stuff
     self.signalRegister( Light.LIGHT_POSITION_SIGNAL )
     self.signalRegister( Light.LIGHT_DIRECTION_SIGNAL )
     
     # shadow maps for this light
     self.shadowMapArray = None
     
     # TODO: make xml configurable
     self.dimming = 0.3
Esempio n. 6
0
 def create(self, app):
     """
     creates gl resources of model.
     @param lights: list of gl_helper.light.Light instances
     """
     
     GLObject.create(self, app, self.lights)
     
     self.createDrawFunction()
     
     for l in self.lights:
         l.createGuard(app, self.lights)
     for s in self.segments:
         s.createGuard(app, self.lights)
     # TODO: VBO: create some bigger vbos for vbo segments
     
     self.postCreate()
Esempio n. 7
0
 def create(self, app, lights):
     """
     create the shadow maps.
     """
     
     if self.getAttr("useShadowMap", False):
         type = self.getLightType()
         #kernel = ShadowMap.noKernel()
         #kernel = ShadowMap.kernel44()
         if type==Light.POINT_LIGHT:
             # TODO: SM: point light shadows
             raise NotImplementedError
         
         elif type==Light.DIRECTIONAL_LIGHT:
             # directional light needs scene frustum
             app.needFrustumPoints = True
             
             mapSize = 2048.0
             numSplits = 4
             
             self.shadowMapArray = ShadowMapArray(app, app.sceneCamera, mapSize)
             frustas = splitFrustum(app.sceneFrustum, numSplits, 0.75)
             
             for frustum in frustas:
                 camera = DirectionalShadowCamera( app, self, frustum, mapSize )
                 self.shadowMapArray.addShadowMap( DirectionalShadowMap( camera ))
             
         else: # spot light
             mapSize = 2048
             
             self.shadowMapArray = ShadowMapArray(app, app.sceneCamera, mapSize)
             
             camera = SpotShadowCamera(app, self)
             self.shadowMapArray.addShadowMap( SpotShadowMap( camera  ) )
     
     if self.shadowMapArray!=None:
         self.shadowMapArray.create(app)
     
     GLObject.create(self, app, lights)
Esempio n. 8
0
 def create(self, app, lights):
     """
     call after configuration.
     currently only once callable because some vertex data
     calculations cannot get undone (face groups).
     """
     self.app = app
     self.enabledLights = range(len(lights))
     self.lights = lights
     
     self.hidden = False
     
     GLObject.create(self, app, lights)
     
     # material needs to get gl resources for textures
     if self.material != None:
         self.material.createGuard(app, lights)
     
     # splits up creation
     self.createResources()
     self.createResourcesPost()
     self.createShader()
     self.createDrawFunction()
     self.postCreate()
Esempio n. 9
0
 def create(self, app, lights):
     for tex in self.textures:
         tex.create()
     GLObject.create(self, app, lights)
Esempio n. 10
0
    def __init__(self, params):
        GLObject.__init__(self, params)

        self.controlPoints = params.get("ctrls")
        self.params = params.get("params")
        self.target = params.get("target")
Esempio n. 11
0
 def __init__(self,
              winSize=(1024,768),
              modes=OPENGL|DOUBLEBUF|HWSURFACE,
              nearClip=1.0,
              farClip=200.0,
              fov=45.0,
              caption='OpenGL fun',
              iconName=None,
              useJoysticks=[0],
              hideCursor=False):
     '''
     Constructor, opens the window and initials opengl/pygame.
     '''
     
     GLObject.__init__(self, {})
     # signal stuff
     self.signalRegister( GLApp.APP_SIZE_SIGNAL )
     self.signalRegister( GLApp.APP_PROJECTION_CHANGED )
     
     self.modes = modes
     self.winSize = winSize
     
     self.timePassed = 0
     self.FPS = 0
     
     self.farClip  = farClip
     self.nearClip = nearClip
     self.fov      = fov
     
     self.caption = caption
     
     self.sceneBounds = None
     
     # save the projection for faster calculations
     self.projectionMat = None
     
     pygame.init()
     
     # init display
     pygame.display.gl_set_attribute(pygame.GL_RED_SIZE,   8)
     pygame.display.gl_set_attribute(pygame.GL_GREEN_SIZE, 8)
     pygame.display.gl_set_attribute(pygame.GL_BLUE_SIZE,  8)
     pygame.display.gl_set_attribute(pygame.GL_ALPHA_SIZE, 8)
     # vsync
     pygame.display.gl_set_attribute(pygame.GL_SWAP_CONTROL, 1)
     
     (self.screen, self.winSize) = self.setWindowSize(winSize)
     
     print "INFO: OpenGL and PyGame initialed."
     printGLInfo()
     
     # hide cursor for custom mouse drawing
     pygame.mouse.set_visible(not hideCursor)
     
     # lookup joystick devices
     if useJoysticks!=[]:
         numJoysticks = pygame.joystick.get_count()
         self.joypads = []
         
         if not numJoysticks:
             print "WARNING: No joystick connected."
         else:
             if numJoysticks<len(useJoysticks):
                 print "WARNING: Only %d joysticks connected." % numJoysticks
             for x in useJoysticks:
                 if x < numJoysticks:
                     j = pygame.joystick.Joystick(x)
                     self.joypads.append(JoyStick(j))
                     
                     print "INFO: Using joystick: '%s' with %d buttons and %d axes." \
                                 % (j.get_name(), j.get_numbuttons(), j.get_numaxes())
     else:
         self.joypads = []
     
     # set window title
     pygame.display.set_caption(caption)
     # set window icon
     if iconName!=None:
         surface = image.load("../textures/" + iconName)
         pygame.display.set_icon(surface)
     
     self.loadFonts()
     
     self.running = True
     (self.mouseX, self.mouseY) = (0, 0)
     
     self.initGL()
Esempio n. 12
0
 def disableDynamicStates(self):
     GLObject.disableDynamicStates(self)
     for l in self.lights:
         l.disableDynamicStates()
Esempio n. 13
0
 def enableDynamicStates(self):
     GLObject.enableDynamicStates(self)
     for l in self.lights:
         l.enableDynamicStates()
Esempio n. 14
0
 def createDrawFunction(self):
     for l in self.lights:
         l.createDrawFunction()
     GLObject.createDrawFunction(self)
Esempio n. 15
0
 def __init__(self, params, name, dynamic=False):
     self.name = name
     self.dynamic = dynamic
     GLObject.__init__(self, params)
Esempio n. 16
0
    def processFrame(self, timePassedSecs):
        """ draws a scene """

        # update the model view matrix
        self.sceneCamera.updateKeys()
        self.sceneCamera.update()

        # process queued GLObject events
        GLObject.signalsEmit()

        # enable some default scene states
        glEnable(GL_DEPTH_TEST)

        ######## SHADOW MAP RENDERING START ########

        # offset the geometry slightly to prevent z-fighting
        # note that this introduces some light-leakage artifacts
        glEnable(GL_POLYGON_OFFSET_FILL)
        glPolygonOffset(1.1, 4096.0)

        # cull front faces for shadow rendering,
        # this moves z-fighting to backfaces.
        glCullFace(GL_FRONT)
        # enable depth rendering shader.
        # FIXME: support segment geometry shader!
        #          geometry shader could change the shadow shape!
        self.depthShader.enable()

        map(_updateLightShadowMap, self.lights)
        glBindFramebuffer(GL_FRAMEBUFFER, 0)

        glDisable(GL_POLYGON_OFFSET_FILL)
        ######## SHADOW MAP RENDERING STOP ########

        #### TODO: FOG: integrate FOG ####
        glEnable(GL_FOG)
        glFogi(GL_FOG_MODE, GL_EXP2)
        # approximate the atmosphere's filtering effect as a linear function
        sunDir = array([4.0, 4.0, 4.0, 0.0], float32)  # TODO: FOG: what is the sun dir ?
        skyColor = array([0.8, sunDir[1] * 0.1 + 0.7, sunDir[1] * 0.4 + 0.5, 1.0], float32)
        glClearColor(*skyColor)
        glFogf(GL_FOG_DENSITY, 0.4)
        glFogf(GL_FOG_START, 16.0)
        glFogf(GL_FOG_END, self.farClip)
        glFogfv(GL_FOG_COLOR, skyColor)

        # fill projection matrix
        glMatrixMode(GL_PROJECTION)
        glLoadMatrixf(self.projectionMatrix)
        glMatrixMode(GL_MODELVIEW)

        # draw stuff in 3d projection
        lastCam = None
        glPushAttrib(GL_COLOR_BUFFER_BIT)
        for (fbo, draw, cam) in self.sceneFBOS:
            # render to fbo
            fbo.enable()
            if cam != lastCam:
                cam.enable()
                lastCam = cam
            draw()
        # disable render to texture
        FBO.disable()
        glPopAttrib()
        glViewport(0, 0, self.winSize[0], self.winSize[1])

        #### TODO: FOG: integrate FOG ####
        glDisable(GL_FOG)

        # change to orthogonal projection
        glMatrixMode(GL_PROJECTION)
        glLoadMatrixf(self.orthoMatrix)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        # no depth test needed in orthogonal rendering
        glDisable(GL_DEPTH_TEST)

        # draw orthogonal to the screen
        self.orthogonalPass()
Esempio n. 17
0
 def __init__(self, segments, params):
     GLObject.__init__(self, params)
     
     # list of segments
     self.segments = segments
     self.lights = []