View Full Version : Copying OpenGL context to a MemDC (Windows)

11-06-2000, 05:42 AM

I want to make a screenshot (within my program) from the context opengl is painting to.
Therefore I first used the DC of the window, but the problem is, that when another window is painted over my OpenGL window, then the screenshot contains the window above.

So I decided to copy the content of my OpenGL window into a MemoryDC.

What I did is something like

MemDC = CreateCompatibleDC(WindowDC);
wglMakeCurrent(MemDC, m_OpenGL.m_HGLRC);

I hoped that now OpenGL paints into the MemDC but this seems to be wrong. Can someone help me what my mistake is (I am a beginner on DC and OpenGL.. so type slowly :-)

BTW, I am using DoubleBuffer im my function and most of the time the function draws to a window.

Thanks a lot for your help,

11-07-2000, 10:56 AM
You need to go about recreating a GL context for the new DC.


11-07-2000, 11:18 AM
Why not just use glReadPixels? Use that to copy the color buffer into system memory and use its contents as the screenshot.

11-07-2000, 11:22 PM
Originally posted by DFrey:
Why not just use glReadPixels?

According to my book this has the same problems that I am encountering in my current version. If something is above the OpenGL Window it may happen that this is exported too (depending on graphic hardware and drivers)