diff options
Diffstat (limited to 'src/Core/Window.cpp')
| -rw-r--r-- | src/Core/Window.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/Core/Window.cpp b/src/Core/Window.cpp index 73bd8db..d60ebc9 100644 --- a/src/Core/Window.cpp +++ b/src/Core/Window.cpp @@ -2,6 +2,10 @@ #include <cstdint> +#include <imgui.h> +#include <imgui_impl_glfw.h> +#include <imgui_impl_opengl3.h> + namespace Donut { static bool s_GLFWInitialized = false; @@ -66,6 +70,9 @@ namespace Donut void Window::Shutdown() { DONUT_INFO("Shutting down window: ", m_Title); + + ShutdownImGui(); + glfwDestroyWindow(m_Window); s_GLFWWindowCount--; @@ -102,6 +109,61 @@ namespace Donut GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN); } + void Window::InitImGui() + { + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; + io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; + io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; + + ImGui::StyleColorsDark(); + + ImGuiStyle& style = ImGui::GetStyle(); + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + style.WindowRounding = 0.0f; + style.Colors[ImGuiCol_WindowBg].w = 1.0f; + } + + ImGui_ImplGlfw_InitForOpenGL(m_Window, true); + ImGui_ImplOpenGL3_Init("#version 130"); + + DONUT_INFO("ImGUI initialized successfully"); + } + + void Window::ShutdownImGui() + { + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); + + DONUT_INFO("ImGUI shutdown"); + } + + void Window::BeginImGuiFrame() + { + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + } + + void Window::EndImGuiFrame() + { + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + + ImGuiIO& io = ImGui::GetIO(); + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + GLFWwindow* backup_current_context = glfwGetCurrentContext(); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); + glfwMakeContextCurrent(backup_current_context); + } + } + void Window::GLFWErrorCallback(int error, const char* description) { DONUT_ERROR("GLFW Error (", error, "): ", description); |
