Jump to content
  • Advertisement
Sign in to follow this  
Zouflain

OpenGL Extracting texture data

This topic is 4002 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've checked the redbook and google, but I can't find a function that returns a pointer to an array which stores the actual color data within a texture. When creating a texture from a file, one reads the data file, gets a texture name, and inputs the data directly into the texture. I would like to reverse this process - I have the name, and would like to retrieve the stored data (preferably in RGB format). An example use of this code would be generating a texture in OpenGL then exporting it into a BMP. I know the function exists, and it's pretty common I'd imagine, but I don't know it's name or the exact name of the process, and that makes it rather hard to find. I would appreciate any feedback, the exact name of this process, and/or the function name. Thank you for any replies.

Share this post


Link to post
Share on other sites
Advertisement
Hi,
the function you're looking for is glReadPixels.
Here's a sample of how to store a screenshot: http://www.robthebloke.org/opengl_examples/screengrab.zip

I know you want to save a texture and not a screenshot, so this is what you do:
-Enter Orthographic view (glOrtho) with appropriate size (i.e. 800x600)
-Draw a textured quad (as square!) to the screen, lets say from 0x0 to 512x512 (->this will be the texture size)
-then you read this data with glReadPixels(), you need to pass the 512 to this function, too

Threre you are.. you've got the data [wink]

Share this post


Link to post
Share on other sites
No, I don't.

I gave an example of what this could be used for - I never said I wanted to take a screenshot, or even mentioned the word or any of it's synonyms. I only said export a texture to BMP.

Sorry, but when I get snippy answers I get snippy.

Let me clarify.. I have a texture name. I want the RGB data stored in the texture. Drawing the texture on the screen, then grabbing each pixel is unnecessarily slow, and potentially dangerous if something gets drawn over it. It would also add a lot of overhead to draw it to the screen and be able to read from it without the user seeing it.

I mentioned exporting to BMP because you could theoretically use this function for such a thing (in fact, that's probably what it's primary use would be, though not in my case). Thank you for trying to help, though, and thank you Caste for the detailed explanation, but I'm still looking for a function.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zouflain
I gave an example of what this could be used for - I never said I wanted to take a screenshot, or even mentioned the word or any of it's synonyms. I only said export a texture to BMP.

Sorry, but when I get snippy answers I get snippy.



Quote:
Original post by Caste
I know you want to save a texture and not a screenshot, so this is what you do:


Yeh sorry I wrote "save" instead of "get".. But I knew you didnt want a screenshot..

RyanSmith is right.. thats a neater way of doing it.. although mine works too

Share this post


Link to post
Share on other sites
Ah, exactly what I was looking for. Thank you all for your help, and I'm sorry for being grouchy earlier. Truth to be told, I was exhausted after a long day.

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!