So I'm just trying to get things to work, as I'm playing with textures and learning openGl. I'm using python, pygame, and pyopengl. It seems that I just am not getting a texture. I've read a number of tutorials, googled, and can't seem to pin this bug down. I'm probably failing to initialize something.
Heres my loading code. I know that the image is getting loaded because sprite data has a length of 40 some odd kilobytes. Length and width of the image are correctly handled. If I load a long, skinny image with this code, I get a long skinny quad. This is becauseof the last two lines of the first listing.
heres my loading code
mm = dude()
spritesurf = pygame.image.load("soldier.png")
spritedata = pygame.image.tostring(spritesurf,"RGBA")
print len(spritedata)
spritewidth = spritesurf.get_width()
spriteheight = spritesurf.get_height()
mm.sprite = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, mm.sprite)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, spritewidth,spriteheight,0,GL_RGBA,GL_UNSIGNED_BYTE, spritedata)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, spritewidth,spriteheight,0,GL_RGBA,GL_UNSIGNED_BYTE, spritedata)
mm.spritewidth = spritewidth * mm.radius / min(spritewidth,spriteheight)
mm.spriteheight = spriteheight * mm.radius / min(spritewidth,spriteheight)
This is the relevant section of my rendering code:
glBindTexture(GL_TEXTURE_2D, mm.sprite)
glBegin(GL_QUADS)
glTexCoord2f(0,0); glVertex(-mm.spritewidth,-mm.spriteheight ,0)
glTexCoord2f(1,0); glVertex( mm.spritewidth,-mm.spriteheight ,0)
glTexCoord2f(1,1); glVertex( mm.spritewidth, mm.spriteheight ,0)
glTexCoord2f(0,1); glVertex(-mm.spritewidth, mm.spriteheight ,0)
glEnd()