I'm trying to copy the front buffer to the back buffer and also I need to copy the back buffer to the aux0 or aux1 buffer, but I can't get it to work. All I get is a blank copy, not the pixels. I do this right after I swap buffers with: SwapBuffers(glDeviceContext);
This is the code to get the pixels into another buffer:
GLint m_viewport[4];
glGetIntegerv(GL_VIEWPORT, m_viewport);
glReadBuffer(GL_FRONT);
glDrawBuffer(GL_BACK);
glCopyPixels(0, 0, m_viewport[2], m_viewport[3], GL_COLOR);
And I have checked:
glGetError()) != GL_NO_ERROR
So far no errors. But the result is blank. If I just draw again to the back buffer after SwapBuffers(glDeviceContext) I get the desired result, but it means I have to draw twice. I also want to be able to copy the whole buffer into the AUX buffer for system menus, so I have the background of the whole thing.
Here's a short test code:
GLint m_viewport[4];
glGetIntegerv(GL_VIEWPORT, m_viewport);
glReadBuffer(GL_BACK);
glDrawBuffer(GL_AUX2);
glCopyPixels(0, 0, m_viewport[2], m_viewport[3], GL_COLOR);
SwapBuffers(glDeviceContext);
glReadBuffer(GL_AUX2);
glDrawBuffer(GL_BACK);
glCopyPixels(0, 0, m_viewport[2], m_viewport[3], GL_COLOR);
SwapBuffers(glDeviceContext);
Instead of using glCopyPixels
I recommend using framebuffer objects and use glBlitFrameBuffer
or drawing a textured quad to the back buffer, instead of copying the front buffer to the back buffer. In general you should treat both the front and the back buffer as unreliable where the contents might become corrupted at any moment. Essentially if pixels in a window don't pass the pixel ownership test, then both the front and the back buffer at that position are discarded.