Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Enerjak   Members   -  Reputation: 227

Like
0Likes
Like

Posted 27 April 2013 - 01:03 AM

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.



Sponsor:

#2 Sponji   Members   -  Reputation: 1136

Like
0Likes
Like

Posted 27 April 2013 - 02:16 AM

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(
	data,
	width, height, channels,
	SOIL_CREATE_NEW_ID,
	SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT
);

// And remember to free the image data
SOIL_free_image_data(data);

Derp

#3 Enerjak   Members   -  Reputation: 227

Like
0Likes
Like

Posted 27 April 2013 - 08:28 AM

thanks, will use.



#4 mhagain   Crossbones+   -  Reputation: 7413

Like
0Likes
Like

Posted 27 April 2013 - 01:45 PM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS