Read framebuffer pixels without rendering on screen

Started by
2 comments, last by Dustin Hopper 11 years, 11 months ago
I want to read out the color buffer into a memory block of my application in order to implement some features like showing a thumbnail view of the client area, or saving the rendering content of the client area as a disk image fiIe. Our current method is to first render the scene and then call glReadPixels().
However, there is an annoying issue with this method. In my application, there are usually several graphics layers shown in the client area and I need to create one thumbnail for each layer. With the above method, I have to render one graphics layer at a time and then call glReadPixels() to get the buffer pixels for the current layer. The visual result of repeating this two-step process looks like playing PowerPoint slides. So I want to know if there is a method via which I can disable rendering but still get the pixels? Just like press "Ctrl+Q" in Internet Explorer 9 to get thumbnail views for all web pages, without rendering these pages one by one.
Advertisement
I can think of three different approaches to do this. Well depending on what you need. I'm not 100% clear...

glReadBuffer is supposed to let you choose to either read from the FrontBuffer (screen) or the BackBuffer. I think this is what you're looking for.

Alternatively you could also just render to a texture and then display that on an object.

You may also just use glViewPort to define the rendering to a small area of the window so you don't even need to bother about reading pixels from buffers or dealing with textures. This approach isn't as flexible and you'd still need to use one of the others if you want to save the image. But it's probably the fastest...

I can think of three different approaches to do this. Well depending on what you need. I'm not 100% clear...

glReadBuffer is supposed to let you choose to either read from the FrontBuffer (screen) or the BackBuffer. I think this is what you're looking for.

Alternatively you could also just render to a texture and then display that on an object.

You may also just use glViewPort to define the rendering to a small area of the window so you don't even need to bother about reading pixels from buffers or dealing with textures. This approach isn't as flexible and you'd still need to use one of the others if you want to save the image. But it's probably the fastest...


Thanks, the first approach is simple to implement and it works. I will do some search on "render to texture" to see how to do it.
Try using glCopyTexImage2D.

http://www.opengl.org/sdk/docs/man4/xhtml/glCopyTexImage2D.xml

You can specify which buffer to render into, then select said buffer for read operations, then copy directly into a texture.
The texture then can simply be drawn on a quad.
[size=2]hopper.dustin@gmail.com

This topic is closed to new replies.

Advertisement