Jump to content
  • Advertisement
Sign in to follow this  

Getting the width and height (and other data) from a SOIL loaded image.

This topic is 2052 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

Ok, I managed to load a texture using SOIL, but now i need to get the width and height of the texture loaded, plus the bits (like the data). Man, textures in Direct3D are so much easier.

Share this post

Link to post
Share on other sites

I haven't used SOIL, but just looking at the header file's documentation gives you nice information. Have you tried something like this:


int width;
int height
int channels;

// Loads the image and gets its width, height and the number of channels
unsigned char *data = SOIL_load_image("kewltexture.png", &width, &height, &channels, SOIL_LOAD_AUTO);

// Generates a texture from the data you've just loaded
unsigned int textureid = SOIL_create_OGL_texture(
	width, height, channels,

// And remember to free the image data

Share this post

Link to post
Share on other sites

If you have the GLuint texture object, you can glBindTexture it and issue some glGet* calls.


glGetTexLevelParameter: http://www.opengl.org/sdk/docs/man/xhtml/glGetTexLevelParameter.xml - for height and width.

glGetTexImage: http://www.opengl.org/sdk/docs/man/xhtml/glGetTexImage.xml - for data.


In the latter case, I hope you're not intending a usage similar to LockRect/Map in D3D; OpenGL doesn't have API calls for this, so instead you'd use a PBO or retain a copy of the texture data in system memory.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!