Browse Source

Examples: Enable vsync by default in example applications (#1213, #1151)

omar 8 years ago
parent
commit
645875a240

+ 3 - 1
examples/directx10_example/main.cpp

@@ -183,7 +183,9 @@ int main(int, char**)
         // Rendering
         // Rendering
         g_pd3dDevice->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
         g_pd3dDevice->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
         ImGui::Render();
         ImGui::Render();
-        g_pSwapChain->Present(0, 0);
+
+        g_pSwapChain->Present(1, 0); // Present with vsync
+        //g_pSwapChain->Present(0, 0); // Present without vsync
     }
     }
 
 
     ImGui_ImplDX10_Shutdown();
     ImGui_ImplDX10_Shutdown();

+ 3 - 1
examples/directx11_example/main.cpp

@@ -186,7 +186,9 @@ int main(int, char**)
         // Rendering
         // Rendering
         g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
         g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
         ImGui::Render();
         ImGui::Render();
-        g_pSwapChain->Present(0, 0);
+
+        g_pSwapChain->Present(1, 0); // Present with vsync
+        //g_pSwapChain->Present(0, 0); // Present without vsync
     }
     }
 
 
     ImGui_ImplDX11_Shutdown();
     ImGui_ImplDX11_Shutdown();

+ 2 - 1
examples/directx9_example/main.cpp

@@ -63,7 +63,8 @@ int main(int, char**)
     g_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
     g_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
     g_d3dpp.EnableAutoDepthStencil = TRUE;
     g_d3dpp.EnableAutoDepthStencil = TRUE;
     g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
     g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
-    g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
+    g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // Present with vsync
+    //g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Present without vsync, maximum unthrottled framerate
 
 
     // Create the D3DDevice
     // Create the D3DDevice
     if (pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0)
     if (pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0)

+ 1 - 0
examples/opengl2_example/main.cpp

@@ -19,6 +19,7 @@ int main(int, char**)
         return 1;
         return 1;
     GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL2 example", NULL, NULL);
     GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL2 example", NULL, NULL);
     glfwMakeContextCurrent(window);
     glfwMakeContextCurrent(window);
+    glfwSwapInterval(1); // Enable vsync
 
 
     // Setup ImGui binding
     // Setup ImGui binding
     ImGui_ImplGlfw_Init(window, true);
     ImGui_ImplGlfw_Init(window, true);

+ 1 - 0
examples/opengl3_example/main.cpp

@@ -26,6 +26,7 @@ int main(int, char**)
 #endif
 #endif
     GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL);
     GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL);
     glfwMakeContextCurrent(window);
     glfwMakeContextCurrent(window);
+    glfwSwapInterval(1); // Enable vsync
     gl3wInit();
     gl3wInit();
 
 
     // Setup ImGui binding
     // Setup ImGui binding