Jump to content
  • Advertisement
Sign in to follow this  
Browser12

OpenGL Retrieving image data from OpenGL texture?

This topic is 3978 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 very familiar with loading .tga's, but less so with saving them... I'm good up until the last part, the saving of the image data. How can I get the image data from GL using the texture's ID so that I can write it to the file? Is this even possible? Anyways, thanks for reading, and I appreciate your time! :]

Share this post


Link to post
Share on other sites
Advertisement
You are looking for the glGetTexImage function. Something like this should work:


GLint width, height;
char *data;

glBindTexture(GL_TEXTURE_2D, your_texture_id);

glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);

data = malloc(width*height*4);

glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, data);



data should now contain the image data. Already in the format you need for saving it in a 32 bit uncompressed TGA file. Don't forget to free() it. ;)

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!