J
JigglyBit
Guest
Hi,
I just learned how to double buffer graphics from another post and thought that I had everything working fine. I however am running into an odd (probably plain sight that I am overlooking) issue where the background render, once transferred over to the default hdc is displaying everything in the window as a black background after BitBlt() is executed specifying SRCCOPY. The dozens of objects rendered in the buffer HDC are showing up, just the background is black. The parent window has a white background. After playing around I am fairly confident that this function is the cause but can't quite put my finger on why the new HDC, and HBITMAP are responding this way with designation SRCCOPY unless there is an initialization that I am missing. Can someone help fill me in on why this is happening or what device context I am forgetting to initialize or transfer?
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
WCHAR displayWriteBuffer[16];
HBRUSH hbr;
HFONT hfntbold = CreateFont(48, 0, 0, 0, FW_DONTCARE, FALSE, TRUE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Impact"));
HPEN biggun = CreatePen(PS_SOLID, 4, RGB(0, 0, 255));
RECT Display;
HDC backgroundRender; //handle to background buffering device context
HBITMAP backgroundBitmap; //handle to background bitmap to draw
backgroundRender = CreateCompatibleDC(hdc); //create compatible for mapping
backgroundBitmap = CreateCompatibleBitmap(hdc, 600, 400); //create compatible for mapping
SelectObject(backgroundRender, backgroundBitmap); //select background buffer scope for drawing
Display.left = 20; Display.bottom = 60; Display.top = 20; Display.right = 250;
hbr = CreateSolidBrush(RGB(200, 200, 200));
SelectObject(backgroundRender, hbr);
FillRect(backgroundRender, &Display, hbr);
SetBkColor(backgroundRender, RGB(200, 200, 200));
SelectObject(backgroundRender, hfntbold);
DrawText(backgroundRender, DisplayRegisterWCHAR, displayLength, &Display, DT_RIGHT | DT_SINGLELINE | DT_VCENTER);
//draw 3d axis boxes
swprintf_s(displayWriteBuffer, 16, L"%i", AccelArray3A[0]);
Display.left = 20; Display.right = 100; Display.top = 260; Display.bottom = 295;
DrawText(backgroundRender, displayWriteBuffer, 4, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
swprintf_s(displayWriteBuffer, 16, L"%i", AccelArray3A[1]);
Display.left = 110; Display.right = 190; Display.top = 260; Display.bottom = 295;
DrawText(backgroundRender, displayWriteBuffer, 4, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
swprintf_s(displayWriteBuffer, 16, L"%i", AccelArray3A[2]);
Display.left = 200; Display.right = 280; Display.top = 260; Display.bottom = 295;
DrawText(backgroundRender, displayWriteBuffer, 4, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
swprintf_s(displayWriteBuffer, 16, L"%.2f", AccelArrayNormalized[0]);
Display.left = 20; Display.right = 100; Display.top = 300; Display.bottom = 335;
DrawText(backgroundRender, displayWriteBuffer, 5, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
swprintf_s(displayWriteBuffer, 16, L"%.2f", AccelArrayNormalized[1]);
Display.left = 110; Display.right = 190; Display.top = 300; Display.bottom = 335;
DrawText(backgroundRender, displayWriteBuffer, 5, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
swprintf_s(displayWriteBuffer, 16, L"%.2f", AccelArrayNormalized[2]);
Display.left = 200; Display.right = 280; Display.top = 300; Display.bottom = 335;
DrawText(backgroundRender, displayWriteBuffer, 5, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
MoveToEx(backgroundRender, 425, 180, NULL);
LineTo(backgroundRender, 425 - (AccelArrayNormalized[0] * 100), 180);
MoveToEx(backgroundRender, 425, 180, NULL);
LineTo(backgroundRender, 425, 180 -(AccelArrayNormalized[2] * 100));
MoveToEx(backgroundRender, 425, 180, NULL);
SelectObject(backgroundRender, biggun);
LineTo(backgroundRender, 425 - (AccelArrayNormalized[0] * 100), 180 - (AccelArrayNormalized[2] * 100));
BitBlt(hdc, 0, 0, 600, 400, backgroundRender, 0, 0, SRCCOPY); //copy background rendered image to foreground
// TODO: Add any drawing code that uses hdc here...
EndPaint(hWnd, &ps);
DeleteObject(backgroundRender);
DeleteObject(backgroundBitmap);
DeleteObject(biggun);
DeleteObject(hbr);
DeleteObject(hfntbold);
DeleteObject(hdc);
}
Graphics post update.
Continue reading...
I just learned how to double buffer graphics from another post and thought that I had everything working fine. I however am running into an odd (probably plain sight that I am overlooking) issue where the background render, once transferred over to the default hdc is displaying everything in the window as a black background after BitBlt() is executed specifying SRCCOPY. The dozens of objects rendered in the buffer HDC are showing up, just the background is black. The parent window has a white background. After playing around I am fairly confident that this function is the cause but can't quite put my finger on why the new HDC, and HBITMAP are responding this way with designation SRCCOPY unless there is an initialization that I am missing. Can someone help fill me in on why this is happening or what device context I am forgetting to initialize or transfer?
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
WCHAR displayWriteBuffer[16];
HBRUSH hbr;
HFONT hfntbold = CreateFont(48, 0, 0, 0, FW_DONTCARE, FALSE, TRUE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Impact"));
HPEN biggun = CreatePen(PS_SOLID, 4, RGB(0, 0, 255));
RECT Display;
HDC backgroundRender; //handle to background buffering device context
HBITMAP backgroundBitmap; //handle to background bitmap to draw
backgroundRender = CreateCompatibleDC(hdc); //create compatible for mapping
backgroundBitmap = CreateCompatibleBitmap(hdc, 600, 400); //create compatible for mapping
SelectObject(backgroundRender, backgroundBitmap); //select background buffer scope for drawing
Display.left = 20; Display.bottom = 60; Display.top = 20; Display.right = 250;
hbr = CreateSolidBrush(RGB(200, 200, 200));
SelectObject(backgroundRender, hbr);
FillRect(backgroundRender, &Display, hbr);
SetBkColor(backgroundRender, RGB(200, 200, 200));
SelectObject(backgroundRender, hfntbold);
DrawText(backgroundRender, DisplayRegisterWCHAR, displayLength, &Display, DT_RIGHT | DT_SINGLELINE | DT_VCENTER);
//draw 3d axis boxes
swprintf_s(displayWriteBuffer, 16, L"%i", AccelArray3A[0]);
Display.left = 20; Display.right = 100; Display.top = 260; Display.bottom = 295;
DrawText(backgroundRender, displayWriteBuffer, 4, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
swprintf_s(displayWriteBuffer, 16, L"%i", AccelArray3A[1]);
Display.left = 110; Display.right = 190; Display.top = 260; Display.bottom = 295;
DrawText(backgroundRender, displayWriteBuffer, 4, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
swprintf_s(displayWriteBuffer, 16, L"%i", AccelArray3A[2]);
Display.left = 200; Display.right = 280; Display.top = 260; Display.bottom = 295;
DrawText(backgroundRender, displayWriteBuffer, 4, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
swprintf_s(displayWriteBuffer, 16, L"%.2f", AccelArrayNormalized[0]);
Display.left = 20; Display.right = 100; Display.top = 300; Display.bottom = 335;
DrawText(backgroundRender, displayWriteBuffer, 5, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
swprintf_s(displayWriteBuffer, 16, L"%.2f", AccelArrayNormalized[1]);
Display.left = 110; Display.right = 190; Display.top = 300; Display.bottom = 335;
DrawText(backgroundRender, displayWriteBuffer, 5, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
swprintf_s(displayWriteBuffer, 16, L"%.2f", AccelArrayNormalized[2]);
Display.left = 200; Display.right = 280; Display.top = 300; Display.bottom = 335;
DrawText(backgroundRender, displayWriteBuffer, 5, &Display, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
MoveToEx(backgroundRender, 425, 180, NULL);
LineTo(backgroundRender, 425 - (AccelArrayNormalized[0] * 100), 180);
MoveToEx(backgroundRender, 425, 180, NULL);
LineTo(backgroundRender, 425, 180 -(AccelArrayNormalized[2] * 100));
MoveToEx(backgroundRender, 425, 180, NULL);
SelectObject(backgroundRender, biggun);
LineTo(backgroundRender, 425 - (AccelArrayNormalized[0] * 100), 180 - (AccelArrayNormalized[2] * 100));
BitBlt(hdc, 0, 0, 600, 400, backgroundRender, 0, 0, SRCCOPY); //copy background rendered image to foreground
// TODO: Add any drawing code that uses hdc here...
EndPaint(hWnd, &ps);
DeleteObject(backgroundRender);
DeleteObject(backgroundBitmap);
DeleteObject(biggun);
DeleteObject(hbr);
DeleteObject(hfntbold);
DeleteObject(hdc);
}
Graphics post update.
Continue reading...