diff options
| author | hachem <im@hachem.wtf> | 2025-08-14 01:24:24 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2025-08-14 01:24:24 +0200 |
| commit | 4de723231b38d7c7e272e71b9580443874c278ab (patch) | |
| tree | c93be963476510b8af30ffb4af7d69d468926fe3 /src/core/window.cpp | |
| parent | 0d8b874c0048ca088bb9e353a5f7c62e1f8cd0e8 (diff) | |
feat: implement an ImGui layer
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 f598357..df19b86 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_glfw_initialized = false; @@ -66,6 +70,9 @@ namespace Donut void Window::shutdown() { DONUT_INFO("Shutting down window: ", m_title); + + shutdown_im_gui(); + glfwDestroyWindow(m_window); s_glfw_window_count--; @@ -102,6 +109,61 @@ namespace Donut GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN); } + void Window::init_im_gui() + { + 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::shutdown_im_gui() + { + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); + + DONUT_INFO("ImGUI shutdown"); + } + + void Window::begin_im_gui_frame() + { + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + } + + void Window::end_im_gui_frame() + { + 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::glfw_error_callback(int error, const char* description) { DONUT_ERROR("GLFW Error (", error, "): ", description); |
