CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2010
    Posts
    4

    Question [Direct3D 9] Resizing window

    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

  2. #2
    Join Date
    Apr 1999
    Posts
    3,585

    Re: [Direct3D 9] Resizing window

    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.
    Gort...Klaatu, Barada Nikto!

  3. #3
    Join Date
    Feb 2010
    Posts
    4

    Re: [Direct3D 9] Resizing window

    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

  4. #4
    Join Date
    Apr 1999
    Posts
    3,585

    Re: [Direct3D 9] Resizing window

    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?
    Gort...Klaatu, Barada Nikto!

  5. #5
    Join Date
    Feb 2010
    Posts
    4

    Re: [Direct3D 9] Resizing window

    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

  6. #6
    Join Date
    Apr 1999
    Posts
    3,585

    Re: [Direct3D 9] Resizing window

    Please refer to my earlier post. I think you still need to recreate the device with the new window extents.
    Gort...Klaatu, Barada Nikto!

  7. #7
    Join Date
    Feb 2010
    Posts
    4

    Re: [Direct3D 9] Resizing window

    Thank you Mike!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured