void
ScreenCapture(
const
char
*strFilePath )
{
BITMAPFILEHEADER BMFH;
BITMAPINFOHEADER BMIH;
int
nWidth = 0;
int
nHeight = 0;
unsigned
long
dwQuadrupleWidth = 0;
GLbyte *pPixelData = NULL;
#ifdef WIN32
RECT ImageRect;
GetClientRect( *m_hWndCopy, &ImageRect );
nWidth = ImageRect.right - ImageRect.left;
nHeight = ImageRect.bottom - ImageRect.top;
#else
nWidth = 1024;
nHeight = 768;
#endif
dwQuadrupleWidth = ( nWidth % 4 ) ? ( ( nWidth ) + ( 4 - ( nWidth % 4 ) ) ) : ( nWidth );
BMFH.bfType = 0x4D42;
BMFH.bfSize =
sizeof
( BITMAPFILEHEADER ) +
sizeof
( BITMAPINFOHEADER ) + ( dwQuadrupleWidth * 3 * nHeight );
BMFH.bfOffBits =
sizeof
( BITMAPFILEHEADER ) +
sizeof
( BITMAPINFOHEADER );
BMIH.biSize =
sizeof
( BITMAPINFOHEADER );
BMIH.biWidth = nWidth;
BMIH.biHeight = nHeight;
BMIH.biPlanes = 1;
BMIH.biBitCount = 24;
BMIH.biCompression = BI_RGB;
BMIH.biSizeImage = dwQuadrupleWidth * 3 * nHeight;
BMIH.biXPelsPerMeter = 0;
BMIH.biYPelsPerMeter = 0;
BMIH.biClrUsed = 0;
BMIH.biClrImportant = 0;
pPixelData =
new
GLbyte[ dwQuadrupleWidth * 3 * nHeight ];
glReadPixels(
0, 0,
nWidth, nHeight,
GL_BGR,
GL_UNSIGNED_BYTE,
pPixelData
);
{
FILE
*outFile =
fopen
( strFilePath,
"wb"
);
if
( outFile == NULL )
{
}
fwrite
( &BMFH,
sizeof
(
char
),
sizeof
(BITMAPFILEHEADER), outFile );
fwrite
( &BMIH,
sizeof
(
char
),
sizeof
(BITMAPINFOHEADER), outFile );
fwrite
( pPixelData,
sizeof
( unsigned
char
), BMIH.biSizeImage, outFile );
fclose
( outFile );
}
if
( pPixelData != NULL )
{
delete
pPixelData;
}
}