From 09d89439671c361dfea6d9c0ce4d40420e74960d Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 15 Mar 2018 16:42:21 +0100 Subject: [PATCH] Examples Refactor: GLFW: Explicit functions to init GLFW with OpenGL or Vulkan since we cannot read the api hints from glfw. --- examples/imgui_impl_glfw.cpp | 14 ++++++++------ examples/imgui_impl_glfw.h | 2 +- examples/opengl2_example/main.cpp | 2 +- examples/opengl3_example/main.cpp | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index 2b470acd..7197bd5a 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -111,7 +111,7 @@ void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window) glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback); } -bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks) +static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api) { g_Window = window; @@ -163,16 +163,18 @@ bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks) if (io.ConfigFlags & ImGuiConfigFlags_EnableViewports) ImGui_ImplGlfw_InitPlatformInterface(); - g_ClientApi = GlfwClientApi_OpenGL; + g_ClientApi = client_api; return true; } +bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks) +{ + return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_OpenGL); +} + bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks) { - if (!ImGui_ImplGlfw_Init(window, install_callbacks)) - return false; - g_ClientApi = GlfwClientApi_Vulkan; - return true; + return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_Vulkan); } void ImGui_ImplGlfw_Shutdown() diff --git a/examples/imgui_impl_glfw.h b/examples/imgui_impl_glfw.h index c19089d0..84ab937f 100644 --- a/examples/imgui_impl_glfw.h +++ b/examples/imgui_impl_glfw.h @@ -12,7 +12,7 @@ struct GLFWwindow; -IMGUI_API bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks); +IMGUI_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); IMGUI_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); IMGUI_API void ImGui_ImplGlfw_Shutdown(); IMGUI_API void ImGui_ImplGlfw_NewFrame(); diff --git a/examples/opengl2_example/main.cpp b/examples/opengl2_example/main.cpp index 7c5f8d77..2ba7a054 100644 --- a/examples/opengl2_example/main.cpp +++ b/examples/opengl2_example/main.cpp @@ -31,7 +31,7 @@ int main(int, char**) ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls - ImGui_ImplGlfw_Init(window, true); + ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL2_Init(); // Setup style diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 0f943a9a..69ec99a7 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -40,7 +40,7 @@ int main(int, char**) //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls - ImGui_ImplGlfw_Init(window, true); + ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init(); // Setup style