Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Probably the title is confusing, but I didn't know how to ask better, sorry about that. What I would like to do is get a bitmap texture that represents exactly what's rendered at one point in time and save it as a file (I know how to save it, I need only to find out how get the bitmap data form OpenGL) Like a screen shoot, sort of.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

I think that changing the Render Target is what you're looking for. This is also known as "Render to texture".

When you draw stuff in GLES (or GL, or DirectX, or whatever you use), the place the stuff you draw to is called the "Render Target". Usually you render on a backbuffer to be drawn onto the screen, but graphic engines also allow you to draw on a custom render target you can then use as a texture for drawing other stuff.

Custom render textures are the key to enable interesting effects such as mirrors, shadow mapping, PiP, among many others.

Here's another explanation of render buffers, for XNA.

In particular, for GLES, you may want to look at glGenRenderbuffers, glRenderbufferStorage, glBindRenderbuffer and other associated functions.

Here's an example of how to do it in desktop OpenGL.

share|improve this answer
    
You're right, this iswhat i'm looking for, thank you! –  Meda Feb 25 '13 at 3:22
    
@Meda Make sure you read Trevor Powell's answer as well. Changing the render target only helps you when you're going to use the result of a rendering for further rendering, without taking your texture out of the GPU. If you want to pull the pixels out from the GPU back to the CPU, you have to use glReadPixels like Trevor Powell says. –  Panda Pajama Feb 25 '13 at 4:30

glReadPixels can read back pixel values from the framebuffer, which you can then save out to disk.

(Note that you don't want to use glReadPixels normally, as it makes your code stall while the GPU catches up, and reading pixels back from the GPU is usually a rather slow operation. But for the purposes of saving screenshots or debugging rendering issues, it's absolutely what you want to use. If the eventual goal is to feed rendered images back into the rendering system for use as a texture, then Panda's answer is the correct and performance-friendly way to do that. But if you need to get the pixel values back to the CPU so you can save them out, glReadPixels is really the only way to do that.)

share|improve this answer
    
Will keep in mind the glreadpixels function, thanks, would upvote if I could. –  Meda Feb 25 '13 at 3:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.