• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
anders211

saving back buffer on another buffer and present

6 posts in this topic

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?

0

Share this post


Link to post
Share on other sites

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
1

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
0

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).

0

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
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0