• Advertisement
Sign in to follow this  

saving back buffer on another buffer and present

This topic is 1406 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

I have a problem. When I press "P" i my keyboard I want my scene pause (view freeze) - this works

and I want to present dialog box with menu content - this works

The above works however when I do some activity like for example showing content of combobox then as I don't clear back buffer, my view of the scene where the combobox control is placed, is ugly (there is some black rectangular). So my current solution is wrong. I have:

 

void GUI::Display(float timeDelta)
{ 
   if(!e3D->pause)
        (e3D->*(e3D->Display))(timeDelta);
   else
   {
           //pDev->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1, 0); //do not clear when pause
           pDev->BeginScene();


          dialMgr->onRender(timeDelta);


          pDev->EndScene();
          pDev->Present(0, 0, 0, 0); //present back buffer
   }
}
 
and it should be sthm like this:
 
1.) in WndProc during handling "P" I should save back buffer


2.)
void GUI::Display(float timeDelta)
{ 
   if(!e3D->pause)
        (e3D->*(e3D->Display))(timeDelta);
   else
   {
           



           pDev->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1, 0); //clear back buffer


           present saved buffer somehow


           pDev->BeginScene();


          dialMgr->onRender(timeDelta);


          pDev->EndScene();
          pDev->Present(0, 0, 0, 0); //present back buffer
   }
}

Does anybody know how to save back buffer to another buffer and then present it?

Share this post


Link to post
Share on other sites
Advertisement

The "black" area on the screen is not "black" in the backbuffer, and you don't have to do anything like "preserving" the backbuffer - it's still there, it's just not being presented to the screen.

 

When you launch a modal dialog box, you correctly pause the app, which means you're not writing to the screen anymore. Windows is now in charge of drawing the desktop. When your combobox drops down outside of the dialog, it covers up part of another window (your main window client). When the combobox retracts, uncovering that overlapped rectangle, Windows invalidates that rectangle and sends a WM_PAINT to your main window to restore that portion of the screen. The PAINTSTRUCT specified in the WM_PAINT command [edit: the PAINTSTUCT filled by BeginPaint] contains a RECT that corresponds to the (invalidated) overlapped rectangle. I suspect your WM_PAINT response in the main window is something like:
 

    PAINTSTRUCT ps;
    HDC hdc;

    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        EndPaint(hWnd, &ps);
        break;


That response just validates the invalidated rectange but doesn't update the portion of the screen that's "black."

 

You can either live with that "black" rectangle, or modify your main window WM_PAINT response to Present only the invalidated rectangle. If you draw to anything other than the invalidated rectangle, you'll likely get bizarre results.

Edited by Buckeye

Share this post


Link to post
Share on other sites

OK so there is now question how to save back buffer to HBITMAP. The below doesn't work:

 


 
case VK_P: 
        if(gui->e3D->pause) 
{
    gui->e3D->pause = false; 
                             gui->dialMgr->getDialog(MENU_DIALOG_INGAME)->setVisible(false);
                    
}
else 
{
gui->e3D->pause = true; 
gui->dialMgr->getDialog(MENU_DIALOG_INGAME)->setVisible(true);
ReleaseDC(gui->hWnd,gui->hDCWin);
gui->hDCWin=GetDC(gui->hWnd); //remember hDC
}
break;






case WM_PAINT:
 if(gui->e3D != NULL && gui->e3D->pause)
 {
     PAINTSTRUCT ps;
 memset(&ps, 0, sizeof(PAINTSTRUCT));
 BeginPaint(gui->hWnd, &ps);


 //gui->hDCWin=GetDC(gui->hWnd); //this is done earlier when "P" is pressed
 HBITMAP hBMP = CreateCompatibleBitmap(gui->hDCWin, gui->mRes.width, gui->mRes.height); //it should be saved back buffer
              HDC helpDc;
              helpDc=CreateCompatibleDC(NULL);
              SelectObject(helpDc,hBMP); //I suppose that now I have image in helpDc, so just copy it into hDCWin in order to see at the screen
              BitBlt(gui->hDCWin,ps.rcPaint.left,ps.rcPaint.top,ps.rcPaint.right-ps.rcPaint.left,ps.rcPaint.bottom-ps.rcPaint.top,helpDc,ps.rcPaint.left,ps.rcPaint.top,SRCCOPY);
              //ReleaseDC(gui->hWnd,gui->hDCWin); do not release hdc, keep it for future purposes
              DeleteDC(helpDc);
 DeleteObject(hBMP);


              EndPaint(gui->hWnd, &ps);
 }
 else //invoke default action
              DefWindowProc(hWnd, message, wParam, lParam);
          break;
Edited by anders211

Share this post


Link to post
Share on other sites

You can't access the backbuffer from a window. The window doesn't "know" the backbuffer even exists. When the backbuffer is Present'ed, the contents of the backbuffer are copied by the DirectX device to the window's client area. At that point, the backbuffer data and what's on-screen are entirely separate data.

 


CreateCompatibleBitmap(gui->hDCWin, gui->mRes.width, gui->mRes.height); //it should be saved back buffer

It's not the "saved" backbuffer. It's an empty bitmap the size specified, with a color format compatible with the window client area.

 

Even if your code were to work, what you would be doing is making a bmp of what's on-screen, and then blt'ing it right back to the screen. All the various hWnd's and DC's are all for the same window.

 

As a side comment, getting a display context in one area of your program and releasing it elsewhere (particularly when processing a message in the window procedure) is bad practice. There's no reason to "save" one. You can use GetDC anytime you like (with a matching ReleaseDC).

Share this post


Link to post
Share on other sites

I modified a bit my solution and I found what is going wrong. The problem is that WM_PAINT isn't invoked at all!!! It is invoked when I minimize window, but not when I extends/unroll combobox. This is why it doesn't work! So I have to place my code (pasting bitmap into the screen) not in WM_PAINT window, only somewhere else, probably before control rendering. This combobox and all other control are not windows ones, they are rendered by my code like any other graphic. So this is the reason why WM_PAINT isn't invoked.

Edited by anders211

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement