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?
[DX9] Getting size of the window
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
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;
}
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;
}
Get the size from the current back buffer :
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 );
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement