|
@@ -56,6 +56,7 @@ int main(int, char**)
|
|
|
SDL_GetCurrentDisplayMode(0, ¤t);
|
|
|
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_GL_MakeCurrent(window, gl_context);
|
|
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
|
|
|
|
|
// Initialize OpenGL loader
|
|
@@ -84,17 +85,21 @@ int main(int, char**)
|
|
|
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
|
|
|
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
|
|
|
|
|
|
- // Setup Platform/Renderer bindings
|
|
|
- ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
|
|
|
- ImGui_ImplOpenGL3_Init(glsl_version);
|
|
|
-
|
|
|
- // Setup Style
|
|
|
+ // Setup Dear ImGui style
|
|
|
ImGui::StyleColorsDark();
|
|
|
//ImGui::StyleColorsClassic();
|
|
|
|
|
|
+ // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
|
|
|
ImGuiStyle& style = ImGui::GetStyle();
|
|
|
- style.WindowRounding = 0.0f; // When viewports are enabled it is preferable to disable WinodwRounding
|
|
|
- style.Colors[ImGuiCol_WindowBg].w = 1.0f; // When viewports are enabled it is preferable to disable WindowBg alpha
|
|
|
+ if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
|
|
+ {
|
|
|
+ style.WindowRounding = 0.0f;
|
|
|
+ style.Colors[ImGuiCol_WindowBg].w = 1.0f;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Setup Platform/Renderer bindings
|
|
|
+ ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
|
|
|
+ ImGui_ImplOpenGL3_Init(glsl_version);
|
|
|
|
|
|
// Load Fonts
|
|
|
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
|
@@ -178,7 +183,6 @@ int main(int, char**)
|
|
|
|
|
|
// Rendering
|
|
|
ImGui::Render();
|
|
|
- SDL_GL_MakeCurrent(window, gl_context);
|
|
|
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
|
|
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
@@ -189,9 +193,9 @@ int main(int, char**)
|
|
|
{
|
|
|
ImGui::UpdatePlatformWindows();
|
|
|
ImGui::RenderPlatformWindowsDefault();
|
|
|
+ SDL_GL_MakeCurrent(window, gl_context);
|
|
|
}
|
|
|
|
|
|
- SDL_GL_MakeCurrent(window, gl_context);
|
|
|
SDL_GL_SwapWindow(window);
|
|
|
}
|
|
|
|