|
-
April 30th, 2012, 01:00 PM
#1
OpenGL ddbitmap to dibitmap help
Hi All,
I have the following code for taking a 128X128 pixel screenshot in the middle of my openGL window:
Code:
BITMAP glScreenBmp;
HBITMAP hglScreenBmp;
BITMAPINFOHEADER bih;
BITMAPINFO bi;
HDC hdcWin; // dc for the gallery mode window
HDC memHdc; /// create memory dc for creating BMP
mdiDataPtr->hdc = GetDC(mdiDataPtr->hGLWin);
// grab dc for opengl
wglMakeCurrent(mdiDataPtr->hdc,mdiDataPtr->hglrc);
// grab image data
BYTE* imageData;
imageData = (BYTE *) malloc(sizeof(BYTE) *4* 128 *128);
ZeroMemory(imageData, sizeof(BYTE) *4* 128 *128);
glReadPixels((mdiDataPtr->width/2)-64,(mdiDataPtr->height/2)-64,
128, 128, GL_BGRA_EXT,
GL_UNSIGNED_BYTE,imageData);
// deactivate device context
wglMakeCurrent(mdiDataPtr->hdc, 0);
// release device context and rendering context
ReleaseDC(mdiDataPtr->hGLWin,mdiDataPtr->hdc);
// format image data for bmp
hdcWin = GetDC(hwnd); // dc for the gallery mode window
memHdc = CreateCompatibleDC(hdcWin); /// create memory dc for creating BMP
// create DD Bitmap
hglScreenBmp = CreateBitmap(128,128, 1, 24, imageData);
// select object into compatible dc
SelectObject(memHdc, hglScreenBmp);
ZeroMemory(&glScreenBmp, sizeof(BITMAP));
// get the bitmap object
if( sizeof(BITMAP) != GetObjectW(hglScreenBmp,sizeof(BITMAP), &glScreenBmp))
return FALSE;
// populate bitmap header
bih.biSize =sizeof(BITMAPINFOHEADER);
bih.biWidth = glScreenBmp.bmWidth;
bih.biHeight = glScreenBmp.bmHeight;
bih.biPlanes = 1;
bih.biBitCount = glScreenBmp.bmPlanes*glScreenBmp.bmBitsPixel;
bih.biCompression = BI_RGB;
bih.biSizeImage = 0;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
bih.biClrUsed = 0;
bih.biClrImportant = 0;
bih.biSizeImage = 0;
//DWORD dwBmpSize = ((glScreenBmp.bmWidth * bih.biBitCount + 31) / 32) * 4 //*glScreenBmp.bmHeight;
// this call should auto populate the bih.biSizeImage parameter
int scanLines = GetDIBits(hdcWin, hglScreenBmp,0,glScreenBmp.bmHeight,NULL,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
LPBYTE lpBits = (LPBYTE) malloc(bih.biSize);
scanLines = GetDIBits(hdcWin, hglScreenBmp,0,glScreenBmp.bmHeight,lpBits,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
// SAVE BITMAP DATA TO FILE AND SPLASH ONTO STATIC BITMAP CONTROL
/*
*
*
*
*
*
*/
ReleaseDC(hwnd,hdcWin);
DeleteDC(memHdc);
I believe it is grabbing the RGBA data correctly from the OpenGL window, However, the GetDiBits() call returns 0 scanlines and does not populate the size parameter. I have a feeling I am making a mistake when selecting the object to the wrong context, but I amhonestly a little confused about the concept of memory device contexts and non memory DC's
Thanks for any tips I can take!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|