Sign in to follow this  
angelmu88

[DX9] Getting size of the window

Recommended Posts

angelmu88    228
Hi!
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?

Share this post


Link to post
Share on other sites
hupsilardee    491
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
[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;
}

DWORD style = WS_OVERLAPPEDWINDOW &~ WS_THICKFRAME &~ WS_MAXIMIZEBOX;
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;
}
[/code]

Share this post


Link to post
Share on other sites
Alundra    2316
Get the size from the current back buffer :

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

Share this post


Link to post
Share on other sites
mhagain    13430
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.

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