示例#1
0
    def init(self):
        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        gl.glEnableClientState(gl.GL_COLOR_ARRAY)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_POLYGON_SMOOTH)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)

        gl.glCullFace(gl.GL_BACK)
        gl.glEnable(gl.GL_CULL_FACE)

        gl.glClearColor(*self.world.sky_color)

        vs_file = join(path.SOURCE, 'view', 'shaders', 'lighting.vert')
        vs = VertexShader(vs_file)
        fs_file = join(path.SOURCE, 'view', 'shaders', 'lighting.frag')
        fs = FragmentShader(fs_file)
        shader = ShaderProgram(vs, fs)
        shader.compile()
        shader.use()

        # create glyphs for every item added to the world before now
        for item in self.world:
            self.world_add_item(item)
        # create glyphs for every item added after this
        self.world.item_added += self.world_add_item
示例#2
0
 def draw_world(self):
     gl.glEnableClientState(gl.GL_NORMAL_ARRAY)
     self.projection.set_perspective(45)
     self.modelview.set_world()
     for item in self.world:
         if not hasattr(item, 'shape'):
             continue
         glyph = item.glyph
         gl.glPushMatrix()
         if hasattr(item, 'position'):
             gl.glTranslatef(*item.position)
         # TODO: item orientation
         gl.glVertexPointer(
             Glyph.DIMENSIONS, gl.GL_FLOAT, 0, glyph.glvertices)
         gl.glColorPointer(
             Color.NUM_COMPONENTS, gl.GL_UNSIGNED_BYTE, 0, glyph.glcolors)
         gl.glNormalPointer(gl.GL_FLOAT, 0, glyph.glnormals)
         gl.glDrawElements(
             gl.GL_TRIANGLES,
             len(glyph.glindices),
             type_to_enum[glyph.glindex_type],
             glyph.glindices)
         gl.glPopMatrix()