Jump to content
  • Advertisement
Sign in to follow this  
Uphoreum

OpenGL [OGL] Get Texture Dimensions

This topic is 4142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!