Screenshot from an OpenGL Window

Hi, I want to make some Screensho9ts from my Engine. If I use the PrintScreen key I get screenshots with not anything on the screen.
(pressed while drawing process).

So I thought of an solution in the engine.
(like all games)

So, How do I take an Screenshot and write it to a file ?

Is there an tutorial ?

Thanks anyway,

StryX

I’m using MFC to create my app and can use the PrintScreen button to capture the scene.

I’ve never tried using a non MFC project.

Originally posted by stryx:
[b]Hi, I want to make some Screensho9ts from my Engine. If I use the PrintScreen key I get screenshots with not anything on the screen.
(pressed while drawing process).

So I thought of an solution in the engine.
(like all games)

So, How do I take an Screenshot and write it to a file ?

Is there an tutorial ?

Thanks anyway,

StryX[/b]

Hi StryX,
If you want to get a screenshot from your game, why not just render the frame straight to a bitmap? The following code shows how to set up gl to render onto a windows bitmap.

HWND hwnd = ::GetDesktopWindow();
HDC hdc = ::CreateCompatibleDC(NULL);

//set up bitmap info structure
BITMAPINFOHEADER bi;
memset(&bi, 0, sizeof(BITMAPINFOHEADER));
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = width;
bi.biHeight = height;
bi.biPlanes = 1;
bi.biBitCount = 24;
bi.biCompression = BI_RGB;
bi.biSizeImage = widthheight3;

//create bitmap
LPVOID bits;
HBITMAP hbmp = ::CreateDibSection(hdc, (BITMAPINFO*)&bi, DIB_RGB_COLORS, &bits, NULL, 0);

//select the bitmap into the gl device context
::SelectObject(hdc, hbmp);

//set up the pixelformatdescriptor
//pfd.cColorBits must be the same as
//bi.biBitCount
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_BITMAP|PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;

//set up the gl rendering context
int pixelformat = ::ChoosePixelFormat(hdc, &pfd);
::SetPixelFormat(hdc, pixelformat, &pfd);
HGLRC hglrc = ::wglCreateContext(hdc);

::wglMakeCurrent(hdc, hglrc);

RENDER CODE GOES HERE

//paste bitmap onto the clipboard
::OpenClipboard(hwnd);
::EmptyClipboard();
::SetClipboardData(CF_BITMAP, hbmp);
::CloseClipboard();

This code should render your scene to a bitmap, which is then placed on the system clipboard. If you want to write the data to a file you’ll have to write a function to do this - I don’t think there is a standard winapi one.

jimmi

Try this link.
http://www.opengl.org/discussion_boards/ubb/Forum4/HTML/000182.html

Saves as a BMP.