Sign in to follow this  
Uphoreum

OpenGL [OGL] Get Texture Dimensions

Recommended Posts

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)?

Share this post


Link to post
Share on other sites
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,[b]w,h,[/b]0,GL_RGB,GL_UNSIGNED_BYTE,bits);
glTexImage1D(type,0,bpp,[b]w,[/b]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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this