PDA

View Full Version : Get loaded texture's height/width



Darlos9D
07-10-2010, 09:32 PM
I'm working with the latest version of GLUT in Visual Studio C++ 2010. I'm trying to make a 2D game where every object in the game is represented by a rectangle. I want to set it up so the rectangle's dimensions are based off of the height and width of the texture that it uses. I seem to have successfully gotten a texture loaded up and passed in with glTexImage2D and so on. But when actually drawing my polygons, I pull up a texture with glBindTexturefv and then try to call glGetTexLevelParameter twice with the pname parameters GL_TEXTURE_WIDTH/HEIGHT to put the values into a couple floats. But when I check the floats afterward, they're zero.

When I was setting up the bitmap info header earlier on when loading the texture, the height and width values were definitely properly set. I assume this means I'm completely misunderstanding glGetTexLevelParameter. Is there some way to use it to get height and width, or do I need to do something else? Or can I do anything at all?

mhagain
07-11-2010, 11:50 AM
Have you tried a glGetError to see if anything went wrong?

Also - and it really shouldn't matter but I've seen some implementations freak out over it before - maybe try glGetTexLevelParameteriv and read into ints. A texture height or width really can't be floating point anyway.

Darlos9D
07-11-2010, 12:12 PM
I tried the iv version and that didn't work either. I'll see if there's an error. I shoulda thought to do that...

EDIT: I get GL_NO_ERROR. Hrm.

EDIT AGAIN: I figured it out. I was loading my textures before I did glEnable(GL_TEXTURE_2D). Commence facepalm...