#include "gui/gui.hpp" #include "gui/gui_data.hpp" #include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" #include "imgui_impl_opengl3_loader.h" #include "gui/window.hpp" gui::Gui::Gui(gui::GuiData &data) : data(data), font("font/DejaVuSans.ttf") { SPDLOG_DEBUG("Creating GUI"); (void) ImGui::CreateContext(); ImGui::StyleColorsDark(); (void) ImGui::GetIO().Fonts->AddFontFromFileTTF(font.c_str(), 18.0f); (void) ImGui_ImplGlfw_InitForOpenGL(data.get_window().get_window().get(), true); initialized = ImGui_ImplOpenGL3_Init(); SPDLOG_DEBUG("Initialized: {}", initialized); } gui::Gui::~Gui() noexcept { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); } void gui::Gui::render_gui() { if (initialized) { constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar; ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); //TODO GUI { const ImGuiViewport &viewport = *ImGui::GetMainViewport(); ImGui::SetNextWindowPos(viewport.Pos); ImGui::SetNextWindowSize(viewport.Size); } // Never collapsed. (void) ImGui::Begin("Billy", nullptr, flags); ImGui::Text("Hello world!"); ImGui::Text("Average framerate: %.3f ms/frame (%.1f FPS)", 1000.f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); ImGui::End(); ImGui::Render(); } } void gui::Gui::render_gpu() const { if (initialized) { glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } }