Click to See Complete Forum and Search --> : [Direct3D 9] Resizing window
Roxypinky
February 7th, 2010, 07:19 PM
Hello people
I'm currently learning D3D and so far I'm doing good but I ran into a little problem that I'm not sure how to fix. I'm displaying a quad in window mode and when I resize the window the content is stretched. I tried to use IDirect3DDevice9::Reset() but I had 2 problem with that, it's slow and makes the resizing of the window become laggy and still appeared bigger. I wanna be able to see more of my world, not just see it become bigger. I tried to mess up with IDirect3DDevice9::SetViewport and creating a swap chain but it didn't work (I probably didn't do it right).
Does anyone have any advice or could point to a good resource on that subject? (I can't seem to find any)
Thank you
Mike Harnad
February 8th, 2010, 07:40 AM
Since the window extents have changed, you'll need to recreate the device to reflect that change. This can force a perfomance hit, so, you should definitely use a swap chanin. And, you should query the device to ensure that you can create it with hardware acceleration. In my code, I wrote a method that is called whenever I need to release and recreate a new DirectX device.
Roxypinky
February 8th, 2010, 07:31 PM
Thanks for your reply.
I tried the swap chain thing I wasn't able to draw in it... it looked like it was still using the default swap chain (i created the device with a small buffer and everything was still all blurry). Do you know what I was doing wrong?
This was executed every time the window was resized.
D3DPRESENT_PARAMETERS d3dpp = {0};
D3DDISPLAYMODE mode;
if (FAILED(m_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode)))
[...]
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
d3dpp.BackBufferFormat = mode.Format;
d3dpp.BackBufferWidth = (unsigned int) m_backbufferWidth;
d3dpp.BackBufferHeight = (unsigned int) m_backbufferHeight;
d3dpp.hDeviceWindow = m_hWndTarget;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
SAFE_RELEASE(m_swapChain);
if (FAILED(m_d3dDevice->CreateAdditionalSwapChain(&d3dpp, &m_swapChain)))
[...]
else
{
IDirect3DSurface9 *backBuffer;
m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);
m_d3dDevice->CreateDepthStencilSurface((unsigned int) m_backbufferWidth, (unsigned int) m_backbufferHeight, mode.Format, D3DMULTISAMPLE_NONE, 0, false, &backBuffer, 0);
m_d3dDevice->SetRenderTarget(0, backBuffer);
}
Thank you,
-Roxanne
Mike Harnad
February 9th, 2010, 08:07 AM
The code you posted is taken out of context, so, it's difficult to know how you are using it. Are you responding to WM_SIZE and recreating the device?
Roxypinky
February 9th, 2010, 08:29 PM
Yes, this is when I receive WM_SIZE but I'm not recreating the device, I only create a new swap chain with the new size.
Thank you
Mike Harnad
February 10th, 2010, 07:22 AM
Please refer to my earlier post. I think you still need to recreate the device with the new window extents.
Roxypinky
February 11th, 2010, 05:49 PM
Thank you Mike!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.