Browse Source

Examples: Viewport: Moved the "make current GL context" to reduce the amount of call and hopefully be more explicit about viewport enabled vs disabled requirements. (#1542)

omar 6 years ago
parent
commit
62cfdceac1

+ 1 - 1
examples/example_glfw_opengl2/main.cpp

@@ -140,9 +140,9 @@ int main(int, char**)
         {
         {
             ImGui::UpdatePlatformWindows();
             ImGui::UpdatePlatformWindows();
             ImGui::RenderPlatformWindowsDefault();
             ImGui::RenderPlatformWindowsDefault();
+            glfwMakeContextCurrent(window);
         }
         }
 
 
-        glfwMakeContextCurrent(window);
         glfwSwapBuffers(window);
         glfwSwapBuffers(window);
     }
     }
 
 

+ 1 - 2
examples/example_glfw_opengl3/main.cpp

@@ -178,7 +178,6 @@ int main(int, char**)
         // Rendering
         // Rendering
         ImGui::Render();
         ImGui::Render();
         int display_w, display_h;
         int display_w, display_h;
-        glfwMakeContextCurrent(window);
         glfwGetFramebufferSize(window, &display_w, &display_h);
         glfwGetFramebufferSize(window, &display_w, &display_h);
         glViewport(0, 0, display_w, display_h);
         glViewport(0, 0, display_w, display_h);
         glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
         glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
@@ -190,9 +189,9 @@ int main(int, char**)
         {
         {
             ImGui::UpdatePlatformWindows();
             ImGui::UpdatePlatformWindows();
             ImGui::RenderPlatformWindowsDefault();
             ImGui::RenderPlatformWindowsDefault();
+            glfwMakeContextCurrent(window);
         }
         }
 
 
-        glfwMakeContextCurrent(window);
         glfwSwapBuffers(window);
         glfwSwapBuffers(window);
     }
     }
 
 

+ 2 - 1
examples/example_sdl_opengl2/main.cpp

@@ -32,6 +32,7 @@ int main(int, char**)
     SDL_GetCurrentDisplayMode(0, &current);
     SDL_GetCurrentDisplayMode(0, &current);
     SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
     SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
     SDL_GLContext gl_context = SDL_GL_CreateContext(window);
     SDL_GLContext gl_context = SDL_GL_CreateContext(window);
+    SDL_GL_MakeCurrent(window, gl_context);
     SDL_GL_SetSwapInterval(1); // Enable vsync
     SDL_GL_SetSwapInterval(1); // Enable vsync
 
 
     // Setup Dear ImGui context
     // Setup Dear ImGui context
@@ -142,9 +143,9 @@ int main(int, char**)
         {
         {
             ImGui::UpdatePlatformWindows();
             ImGui::UpdatePlatformWindows();
             ImGui::RenderPlatformWindowsDefault();
             ImGui::RenderPlatformWindowsDefault();
+            SDL_GL_MakeCurrent(window, gl_context);
         }
         }
 
 
-        SDL_GL_MakeCurrent(window, gl_context);
         SDL_GL_SwapWindow(window);
         SDL_GL_SwapWindow(window);
     }
     }
 
 

+ 2 - 2
examples/example_sdl_opengl3/main.cpp

@@ -56,6 +56,7 @@ int main(int, char**)
     SDL_GetCurrentDisplayMode(0, &current);
     SDL_GetCurrentDisplayMode(0, &current);
     SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
     SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
     SDL_GLContext gl_context = SDL_GL_CreateContext(window);
     SDL_GLContext gl_context = SDL_GL_CreateContext(window);
+    SDL_GL_MakeCurrent(window, gl_context);
     SDL_GL_SetSwapInterval(1); // Enable vsync
     SDL_GL_SetSwapInterval(1); // Enable vsync
 
 
     // Initialize OpenGL loader
     // Initialize OpenGL loader
@@ -177,7 +178,6 @@ int main(int, char**)
 
 
         // Rendering
         // Rendering
         ImGui::Render();
         ImGui::Render();
-        SDL_GL_MakeCurrent(window, gl_context);
         glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
         glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
         glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
         glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
         glClear(GL_COLOR_BUFFER_BIT);
         glClear(GL_COLOR_BUFFER_BIT);
@@ -188,9 +188,9 @@ int main(int, char**)
         {
         {
             ImGui::UpdatePlatformWindows();
             ImGui::UpdatePlatformWindows();
             ImGui::RenderPlatformWindowsDefault();
             ImGui::RenderPlatformWindowsDefault();
+            SDL_GL_MakeCurrent(window, gl_context);
         }
         }
 
 
-        SDL_GL_MakeCurrent(window, gl_context);
         SDL_GL_SwapWindow(window);
         SDL_GL_SwapWindow(window);
     }
     }