XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

How to handle WM_SIZE event

Last post 19/08/2007 15:24 by cloud. 1 replies.
  • 19/08/2007 8:03

    How to handle WM_SIZE event

    I have this function that initializes my 3d that gets called in the WM_CREATE event:

    ID3D10Device *Device = NULL;
    IDXGISwapChain *SwapChain = NULL;
    ID3D10RenderTargetView *RenderTargetView = NULL;



    HRESULT InitDevice(HWND hwnd)
    {
      HRESULT hr;  RECT rc;
      GetClientRect(hwnd, &rc);

      DXGI_SWAP_CHAIN_DESC sd;
      ZeroMemory(&sd, sizeof(sd));
    sd.BufferCount = 1;
    sd.BufferDesc.Width = (rc.right - rc.left);
    sd.BufferDesc.Height = (rc.bottom - rc.top);
    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    sd.BufferDesc.RefreshRate.Numerator = 60;
    sd.BufferDesc.RefreshRate.Denominator = 1;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.OutputWindow = hwnd;
    sd.SampleDesc.Count = 1;
    sd.SampleDesc.Quality = 0;
    sd.Windowed = TRUE;
      
      hr = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_DEBUG,
    D3D10_SDK_VERSION, &sd, &SwapChain, &Device);
      if(FAILED(hr)) return hr;

      //create a render target view
    ID3D10Texture2D *buffer;
    hr = SwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&buffer);
    if(FAILED(hr)) return hr;

    hr = Device->CreateRenderTargetView(buffer, NULL, &RenderTargetView);
    buffer->Release();
    if(FAILED(hr)) return hr;

      Device->OMSetRenderTargets(1, &RenderTargetView, NULL);

      //create the viewport
      D3D10_VIEWPORT vp;
    vp.Width = (rc.right - rc.left);
    vp.Height = (rc.bottom - rc.top);
    vp.MinDepth = 0.0f;
    vp.MaxDepth = 1.0f;
    vp.TopLeftX = 0;
    vp.TopLeftY = 0;
    Device->RSSetViewports(1, &vp);

      return S_OK;
    }

    My question is: What happens in the WM_SIZE event? Do I have to release the devices and call this function again with the new width and height of the window? Do I have to just recreate the viewport (but then the backbuffer size would be wrong right?).

  • 19/08/2007 15:24 In reply to

    Re: How to handle WM_SIZE event

    Answer
    Reply Quote
    You need to release the old render target view and then call IDXGISwapChain::ResizeBuffers.  Then recreate the render target view.  Also reset the viewport.  Do similar things for the depth/stencil buffer (just recreate it).
Page 1 of 1 (2 items) Previous Next