Copying OpenGL context to a MemDC (Windows)

Hello,

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);

OnDraw()
{
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 :slight_smile:

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,
Heiko

You need to go about recreating a GL context for the new DC.

Siwko

Why not just use glReadPixels? Use that to copy the color buffer into system memory and use its contents as the screenshot.

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)

Heiko