Browse Source

Improve resizing in dx11 example (#3057)

Make the dx11 example implementation resize the window in a sane way, i.e. not the stretching/scaling the initial render to fit the new window size (current behaviour).
joeslay 5 years ago
parent
commit
a0f01d2290
1 changed files with 9 additions and 0 deletions
  1. 9 0
      examples/example_sdl_directx11/main.cpp

+ 9 - 0
examples/example_sdl_directx11/main.cpp

@@ -101,6 +101,15 @@ int main(int, char**)
                 done = true;
             if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
                 done = true;
+            if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED)
+            {                
+                g_pd3dDeviceContext->OMSetRenderTargets(0, 0, 0);
+                // Release all outstanding references to the swap chain's buffers.
+                g_mainRenderTargetView->Release();
+
+                g_pSwapChain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);
+                CreateRenderTarget();
+            }
         }
 
         // Start the Dear ImGui frame