Files
Archimedes/modules/examples/GuiModules/TestImgui/src/TestImgui.cpp
2025-03-31 13:49:00 -05:00

65 lines
1.7 KiB
C++

#include "TestImgui.h"
#include "imgui.h"
#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"
#include <GLFW/glfw3.h>
TestImgui::TestImgui(void* h, Archimedes::App* a) : Archimedes::GuiModule(h, a) {
name = "TestImgui";
}
TestImgui::~TestImgui() {
windowModule->removeRenderCmd(rcmd);
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
void TestImgui::onLoad() {
IMGUI_CHECKVERSION();
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
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(windowModule->getWindowImpl().getWindow(), true);
ImGui_ImplOpenGL3_Init("#version 330");
rcmd = windowModule->addRenderCmd([](){
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
/*if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}*/
});
}
void TestImgui::run() {
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
if(demo)
ImGui::ShowDemoWindow(&this->demo);
else
app->end();
ImGui::Render();
}