83 lines
2.3 KiB
C++
83 lines
2.3 KiB
C++
#include "ImguiModule.h"
|
|
|
|
#include "modules/WindowModule/src/WindowModule.h"
|
|
|
|
#include "backends/imgui_impl_glfw.h"
|
|
#include "backends/imgui_impl_opengl3.h"
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include "pch.hpp"
|
|
|
|
ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) {
|
|
|
|
name = "ImguiModule";
|
|
|
|
WindowModule* wm = new WindowModule(a, h);
|
|
deps[*wm] = wm;
|
|
}
|
|
|
|
ImguiModule::~ImguiModule() {
|
|
|
|
if(app) {
|
|
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
|
|
|
wm->getRenderer()->getCmdList().erase(rcmd_it);
|
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
ImGui_ImplGlfw_Shutdown();
|
|
ImGui::DestroyContext();
|
|
}
|
|
}
|
|
|
|
void ImguiModule::onLoad() {
|
|
|
|
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
|
|
|
if(!wm) {
|
|
std::cout << "No WindowModule for ImguiModule!\n";
|
|
std::abort();
|
|
}
|
|
|
|
IMGUI_CHECKVERSION();
|
|
context = ImGui::CreateContext();
|
|
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
|
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
|
|
|
|
#ifdef CUSTOMFONT
|
|
io.Fonts->AddFontFromFileTTF(STRINGIZE_VALUE_OF(CUSTOMFONT), 13.0f);
|
|
#endif
|
|
// Setup Dear ImGui style
|
|
ImGui::StyleColorsDark();
|
|
//ImGui::StyleColorsLight();
|
|
|
|
// Setup Platform/Renderer backends
|
|
if(!ImGui_ImplGlfw_InitForOpenGL(wm->getWindow()->getWindowImpl().getWindow(), true))
|
|
std::cout << "GLFWImpl failed\n";
|
|
if(!ImGui_ImplOpenGL3_Init("#version 330")) {
|
|
std::cout << "ImGui_ImplOpenGL3_Init failed!\n" << std::endl;
|
|
}
|
|
|
|
|
|
wm->getRenderer()->getCmdList().push_back([](){
|
|
ImGui::Render();
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
ImGui::NewFrame();
|
|
});
|
|
|
|
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
|
|
|
|
//Compute first frame ahead of first WindowModule->run()
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
ImGui::NewFrame();
|
|
}
|