[OGL] Get Texture Dimensions

Started by
1 comment, last by Kalidor 16 years, 11 months ago
I'm sorry if this question has been asked before, and I'd be surprised if it hasn't, but I couldn't find an answer with a search. I'm just learning SDL + OpenGL, and I need to find the texture dimensions after I've done away with the SDL_Surface. I'm still not exactly sure how the texture system works in OpenGL, but I create a GLuint that is used to reference the texture by using glBindTexture. So, since the GLuint doesn't actually contain any image information, how can I retrieve the dimensions of the texture? Something like glGetTextureDimensions or something (although I couldn't find anything like that)?
Advertisement
Actually you need to supply the source code of the part where you load textures, for you need to specify the dimensions of the texture when you generate it, take this as an example

glTexImage2D(type,0,bpp,w,h,0,GL_RGB,GL_UNSIGNED_BYTE,bits);glTexImage1D(type,0,bpp,w,0,GL_RGB,GL_UNSIGNED_BYTE,bits);


in the code above we specify the w and h of the texture so obviously you have know the width and height of the texture in the code and there you will find your answer.

Also if you convert SDL_surface to a texture then you can get the width and height of the texture using the variables

SDL_surface *surface;int w=surface->w;int h=surface->h;


Hope that helps.
You need to know the width at some point when you're creating the texture, so why not just store it somewhere (or don't do away with the SDL_Surface). If for some odd reason that's not an option, the way to query it from OpenGL is with glGetTexLevelParameter.

This topic is closed to new replies.

Advertisement