Hi,
I’m trying to read the pixels from the backbuffer using gl_ReadPixels. I want to create a snapshot of the current back buffer and write it to a bitmap file. I can easy use the glReadPixels to read the data of the current opengl screen, but if another window is on top of this opengl window, then the pixels of the opengl window beneath it are not correctly read.
Does someone has a solution?
Thank you both for your inputs. As michael said I can use the glReadPixels from the bach buffer too. How can I do that?
ZBuffer, you say that in the backbuffer you I will have the same problem. Something to do with windows and clipping (some sort of optimalisation I presume). By the way, I’ve just downloaded your code examples. I don’t know what they do at the moment, but I will have a look at them soon.
This falls under pixel ownership test.
Check the OpenGL 2.0 specs chapter 4.1.1
“The first test is to determine if the pixel at location (xw, yw) in the framebuffer
is currently owned by the GL (more precisely, by this GL context). If it is not,
the window system decides the fate the incoming fragment. Possible results are
that the fragment is discarded or that some subset of the subsequent per-fragment
operations are applied to the fragment. This test allows the window system to
control the GL’s behavior, for instance, when a GL window is obscured.”
All buffers composing a the bits of a “pixel” in OpenGL (front, back, depth, stencil, etc.) are affected.
Even if reading the backbuffer works on some implementations, that doesn’t mean it will work on others. Implementations which share the back and depth buffer among OpenGL windows will handle the pixel ownership according to the clipping situation.
Use pbuffers for unclipped rendering.
The current draw and read buffers are set with glDrawBuffer and glReadBuffer. For double buffered pixelformats both are initially set to back.