#include "ImGuiLayer.h" #include "Core/Application.h" #include "imgui.h" #include "backends/imgui_impl_glfw.h" #include "backends/imgui_impl_opengl3.h" #include "implot.h" #include "GLFW/glfw3.h" #include "glad/glad.h" namespace Daqromancy { ImGuiLayer::ImGuiLayer() : Layer("ImGuiLayer") { } ImGuiLayer::~ImGuiLayer() {} void ImGuiLayer::OnAttach() { IMGUI_CHECKVERSION(); DY_INFO("Creating ImGui Context..."); ImGui::CreateContext(); ImPlot::CreateContext(); //enable docking and viewports ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; ImGui::StyleColorsDark(); //Hacker mode ImPlot::StyleColorsDark(); ImGuiStyle& style = ImGui::GetStyle(); if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { style.WindowRounding = 0.0f; style.Colors[ImGuiCol_WindowBg].w = 1.0f; } Application& app = Application::GetInstance(); GLFWwindow* window = static_cast(app.GetWindow().GetNativeWindow()); ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init("#version 410"); //GLSL version DY_INFO("Finished creating ImGui Context"); } void ImGuiLayer::OnDetach() { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImPlot::DestroyContext(); ImGui::DestroyContext(); } void ImGuiLayer::Begin() { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); } void ImGuiLayer::End() { Application& app = Application::GetInstance(); ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = ImVec2((float)app.GetWindow().GetWidth(), (float)app.GetWindow().GetHeight()); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { GLFWwindow* backup_current_context = glfwGetCurrentContext(); ImGui::UpdatePlatformWindows(); ImGui::RenderPlatformWindowsDefault(); glfwMakeContextCurrent(backup_current_context); } } void ImGuiLayer::OnImGuiRender(double timestep) { //Demo's used to figure out how to do things. //Should not be on for actual NavProject for //real use //static bool show = true; //ImGui::ShowDemoWindow(&show); } }