Take the 2-minute tour ×

I am playing around with some old OpenGL code and I am having some issues with this...

glGetTexParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &glW);
glGetTexParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &glH);

Now I am new to OpenGL but I am guessing this grabs the height and width of the texture. The problem is, OpenGLES doesn't have GL_TEXTURE_WIDTH or HEIGHT. Now I know that the first answer everyone is going to give is "you need to manage this yourself", however, this is a pretty large code base and it would take some serious time to figure this out.

My question is...

How can I get the width/height of a texture in OpenGLES?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Obvious reaction question: why do you need this information?

Obvious question aside, texture size is not directly exposed. The best you're probably going to be able to do is to use glTexSubImage checking for GL_INVALID_VALUE to search for the size — my reading of the GLES man page is that width = height = 0 isn't an error condition so you can hunt for the greatest (x,y) that's accepted without actually uploading any data.

share|improve this answer
I appreciate your reaction, as I am sure it is the proper one but I am relatively new to all this (OpenGL and even C for that matter) it may take some time. So since it will take some time I have put it on the back burner until I get the port to work then I will revisit. I will try to use the glTexSubImage and see if I can make it do what I am looking for, thanks again! –  Jackie Apr 16 '13 at 17:19
The only thing prompting the question is that OpenGL has a normalised coordinate system, so once uploaded textures always have coordinates between 0 and 1. That's not to say you don't sometimes want to know the size — e.g. if you wrote a Gaussian blur, or any other kernel convolution, as a shader you'd end up effectively needing to know the pixel size of the texture. So the question was more to try to elicit whether there was any other relevant advice that could be given than as a criticism. It's only on reading it back that I realise how harsh it looks. –  Tommy Apr 16 '13 at 19:11
No prob, I've heard way harsher and besides clearly you are very knowledgable so I can take a little criticism :-). I am actually trying to port over prboom+ to OpenGLES on Android and it was in a gl rendering somewhere. I think it was a sprite or something image based so I assumed it wanted the info to draw it the right size. I had to convert it over to glReadBuffer so I was assuming I would use the same values for height and width there but maybe I am thinking about something wrong. –  Jackie Apr 16 '13 at 20:25
add comment

Your Answer


