//
// Created by sebastian on 02.08.26.
//

#include "ImGuiContext.h"

#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"

engine::ImGuiContext::ImGuiContext(Window &window) {
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImGui::StyleColorsDark();
    ImGui::GetIO().IniFilename = nullptr; // keine imgui.ini neben der exe, optional

    ImGui_ImplGlfw_InitForOpenGL(window.getHandle(), /* install_callbacks = */ false);
    ImGui_ImplOpenGL3_Init("#version 460");
}

engine::ImGuiContext::~ImGuiContext() {
    ImGui_ImplOpenGL3_Shutdown();
    ImGui_ImplGlfw_Shutdown();
    ImGui::DestroyContext();
}

void engine::ImGuiContext::beginFrame() const {
    ImGui_ImplOpenGL3_NewFrame();
    ImGui_ImplGlfw_NewFrame();
    ImGui::NewFrame();
}

void engine::ImGuiContext::endFrame() const {
    ImGui::Render();
    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
