Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

[DX9] Getting size of the window

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 angelmu88   Members   


Posted 25 January 2012 - 04:23 AM

I'm currently adding post-effects support to my DirectX 9 based Engine. I want to create a render target texture with the exact size of the window (I want a full-screen post-effect). So far I've been extracting window's size with GetClientRect() function, the problem is that te previous function only return client area's size, so, for instance, if I have a 800x600 resolution this function returns 790x590. What function do I have to use to get 800x600?

#2 hupsilardee   Members   


Posted 25 January 2012 - 04:41 AM

Your client area might not actually be 800x600. When you call CreateWindow (or CreateWindowEx), the values passed in for x, y, w, h, are used to determine the size of the entire window, so the client area will be smaller because of the window's border.

If you then don't set the BackBufferWidth/Height members of the D3DPRESENT_PARAMS struct used to create the device, it will take the client area's size by default as the size of the backbuffer.

To remedy this, you need to resize the window after creating it, but before creating the device, so that the client area is exactly 800x600 (or 1280x720, etc). There's a handy Win32 API function for this, called AdjustWindowRect. Here's an example in my window creation code

HWND CreateGameWindow(int width, int height)
    WNDCLASS wc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW+1;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hInstance = NULL;
    wc.lpfnWndProc = MsgProc;
    wc.lpszClassName = "xeWndCls";
    wc.lpszMenuName = "menu";
    wc.style = CS_HREDRAW | CS_VREDRAW;
    if (!RegisterClass(&wc))
        return NULL;

    RECT wnd = { 0, 0, width, height };
    RECT dt;
    GetClientRect(GetDesktopWindow(), &dt);
    AdjustWindowRect(&wnd, style, FALSE);
    int w = (wnd.right - wnd.left);
    int h = (wnd.bottom - wnd.top);
    int x = ((dt.right - dt.left) - w) / 2;
    int y = ((dt.bottom - dt.top) - h) / 2;
    HWND hWnd = CreateWindow("xeWndCls", "XEngine", style, x, y, w, h, NULL, NULL, NULL, NULL);
    if (hWnd == NULL)
        return NULL;
    ShowWindow(hWnd, SW_SHOW);
    return hWnd;

#3 Alundra   Members   


Posted 25 January 2012 - 04:46 AM

Get the size from the current back buffer :

IDirect3DSurface9* pSurface;
pD3D9Device->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurface );
pSurface->GetDesc( &SurfaceDesc );
UINT Width = SurfaceDesc.Width;
UINT Height = Surface.Height;
SAFE_RELEASE( pSurface );

#4 mhagain   Members   


Posted 25 January 2012 - 05:56 AM

The window client rect is actually the correct size that you want. If your backbuffer size is different then D3D will need to do a stretching operation during Present, which may slow things down quite a bit. Important to ensure that they're both consistently sized.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.