PDA

View Full Version : Screenshot from an OpenGL Window



stryx
04-30-2002, 04:44 AM
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

Pops
04-30-2002, 04:56 AM
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.

jimmi
04-30-2002, 05:26 AM
Originally posted by stryx:
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

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 = width*height*3;

//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

thelamberto
05-01-2002, 02:05 AM
Try this link.
http://www.opengl.org/discussion_boards/ubb/Forum4/HTML/000182.html

Saves as a BMP.