Screen shots with OPenGL
- From: Raghavendra <Raghavendra@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 2 Sep 2008 10:23:13 -0700
I am trying to get a screenshot of a window with usage glReadPixels API's
exposed from OPenGLafter getting the current context. But if I move another
application window above my application window, the screen shot which i get
gets blurred and I get a screen shot which gets overlapped. My code is as
below
RECT r;
GetClientRect(g_windowRef,&r);
CRect rect(r);
CSize size(rect.Width(),rect.Height());
const int bytesPerPixel = 3;
int bytesPerRow = (bytesPerPixel * rect.Width() + 3) & ~3;
int NbBytes = bytesPerRow * rect.Height();
BITMAPINFO bmi;
BITMAPINFOHEADER header;
bmi.bmiHeader.biWidth = size.cx;
bmi.bmiHeader.biHeight = size.cy;
bmi.bmiHeader.biSizeImage = NbBytes;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = bytesPerPixel * 8; // RGB
bmi.bmiHeader.biCompression =0;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
HANDLE handle = (HANDLE)::GlobalAlloc (GHND,sizeof(BITMAPINFOHEADER) +
NbBytes);
char *pData = NULL;
if(handle != NULL)
{
// Lock handle
pData = (char *) ::GlobalLock((HGLOBAL)handle);
// Copy header and data
memcpy(pData, &bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
// Copy from OpenGL
glReadPixels(0, size.cx,size.cy,0,
GL_BGR_EXT,GL_UNSIGNED_BYTE,
pData + sizeof(BITMAPINFOHEADER));
// Unlock::GlobalUnlock((HGLOBAL)handle);
// Push DIB in
clipboard
OpenClipboard(g_windowRef);
EmptyClipboard();
SetClipboardData(CF_DIB,handle);
CloseClipboard();
}
.
- Follow-Ups:
- Re: Screen shots with OPenGL
- From: Richard [Microsoft Direct3D MVP]
- Re: Screen shots with OPenGL
- Prev by Date: RE: DMO related
- Next by Date: Full-screen, exclusive-mode video and D3D debugging
- Previous by thread: RE: DMO related
- Next by thread: Re: Screen shots with OPenGL
- Index(es):
Relevant Pages
|