コード例 #1
0
ファイル: physics.py プロジェクト: fathat/a-murder-of-crows
 def draw(self, instance):
     
     gl = pyglet.gl.gl
     
     gl.glPushMatrix()
     gl.glTranslatef(instance.body.position.x, instance.body.position.y, 0)
     gl.glRotatef(graphics.degree(instance.body.angle), 0, 0, 1)
     
     if not self._display_list:
         self._display_list = gl.glGenLists(1)
         gl.glNewList(self._display_list, gl.GL_COMPILE)
         
         if self._texture:
             gl.glEnable(self._texture.target)        # typically target is GL_TEXTURE_2D
             gl.glBindTexture(self._texture.target, self._texture.id)
             gl.glColor4f(1,1,1,1)
         
         gl.glBegin(gl.GL_POLYGON)
         for v in self._vertices:
             if self._texture:
                 gl.glTexCoord2f(v[2], v[3])
             gl.glVertex2f(v[0], v[1])
         gl.glEnd()
         
         if self._texture:
             gl.glDisable(self._texture.target)        # typically target is GL_TEXTURE_2D
         #pyglet.graphics.draw_indexed(
         #        len(self._vertices)//2,
         #        pyglet.gl.GL_POLYGON,
         #        range(len(self._vertices)//2),
         #        ('v2f', self._vertices))
         gl.glEndList()
     
     gl.glCallList(self._display_list)
     gl.glPopMatrix()
コード例 #2
0
ファイル: spritey.py プロジェクト: fathat/a-murder-of-crows
 def draw(self):
     gl = pyglet.gl.gl
     v = self.vertices
     texture = self.texture
     gl.glEnable(texture.target)        # typically target is GL_TEXTURE_2D
     gl.glBindTexture(texture.target, texture.id)
     gl.glPushMatrix()
     gl.glTranslatef(self.body.position.x, self.body.position.y, 0)
     if self.angle:
         angle = self.angle
     else:
         angle = self.body.angle
     gl.glRotatef(graphics.degree(angle), 0, 0, 1)
     gl.glBegin(gl.GL_QUADS)
     gl.glTexCoord2f(0, 0)
     gl.glVertex2f(v[0][0], v[0][1])
     gl.glTexCoord2f(1, 0)
     gl.glVertex2f(v[1][0], v[1][1])
     gl.glTexCoord2f(1, 1)
     gl.glVertex2f(v[2][0], v[2][1])
     gl.glTexCoord2f(0, 1)
     gl.glVertex2f(v[3][0], v[3][1])
     gl.glEnd()
     gl.glPopMatrix()
     
     gl.glDisable(texture.target)