Skip to content

Instantly share code, notes, and snippets.

@orlp
Created January 2, 2012 11:55
Show Gist options
  • Select an option

  • Save orlp/1550424 to your computer and use it in GitHub Desktop.

Select an option

Save orlp/1550424 to your computer and use it in GitHub Desktop.
cdef int vertices[8]
cdef int texcoords[8]
if self.texture.target == GL_TEXTURE_RECTANGLE_ARB:
# 0, 0
texcoords[0] = 0
texcoords[1] = 0
# 0, tex_height
texcoords[2] = 0
texcoords[3] = self.texture.height
# tex_width, tex_height
texcoords[4] = self.texture.width
texcoords[5] = self.texture.height
# tex_width, 0
texcoords[6] = self.texture.width
texcoords[7] = 0
else:
# 0, 0
texcoords[0] = 0
texcoords[1] = 0
# 0, 1
texcoords[2] = 0
texcoords[3] = 1
# 1, 1
texcoords[4] = 1
texcoords[5] = 1
# 1, 0
texcoords[6] = 1
texcoords[7] = 0
# 0, 0
vertices[0] = 0
vertices[1] = 0
# 0, tex_height
vertices[2] = 0
vertices[3] = self.texture.height
# tex_width, tex_height
vertices[4] = self.texture.width
vertices[5] = self.texture.height
# tex_width, 0
vertices[6] = self.texture.width
vertices[7] = 0
glEnable(self.texture.target)
glBindTexture(self.texture.target, self.texture.id)
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glTexCoordPointer(2, GL_INT, 0, texcoords)
glVertexPointer(2, GL_INT, 0, vertices)
glPushMatrix()
glColor4f(self.red, self.green, self.blue, self.alpha)
if self.x != 0 or self.y != 0:
glTranslatef(int(self.x), int(self.y), 0.0)
if self.rotation != 0:
glRotatef(self.rotation, 0.0, 0.0, 1.0)
if self.scale_x != 0 or self.scale_y != 0:
glScalef(self.scale_x, self.scale_y, 1.0)
if self.anchor_x != 0 or self.anchor_y != 0:
glTranslatef(-int(self.anchor_x), -int(self.anchor_y), 0.0)
glDrawArrays(GL_QUADS, 0, 4)
glPopMatrix()
glDisableClientState(GL_VERTEX_ARRAY)
glDisableClientState(GL_TEXTURE_COORD_ARRAY)
glDisable(self.texture.target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment