// Minimal test for ImGui + GLFW + OpenGL #include // ImGui includes #include "include/imgui/imgui.h" #include "include/imgui/imgui_impl_glfw.h" #include "include/imgui/imgui_impl_opengl3.h" // GLAD and GLFW #include "glad/glad.h" #include "include/glfw/glfw3.h" int main() { // Initialize GLFW if (!glfwInit()) { std::cerr << "Failed to initialize GLFW" << std::endl; return 1; } // Configure GLFW glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Create window GLFWwindow* window = glfwCreateWindow(800, 600, "ImGui Test", NULL, NULL); if (!window) { std::cerr << "Failed to create GLFW window" << std::endl; glfwTerminate(); return 1; } glfwMakeContextCurrent(window); glfwSwapInterval(1); // Enable vsync // Initialize GLAD if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { std::cerr << "Failed to initialize GLAD" << std::endl; return 1; } // Setup Dear ImGui IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGui::StyleColorsDark(); // Setup Platform/Renderer backends ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init("#version 330"); // Main loop while (!glfwWindowShouldClose(window)) { glfwPollEvents(); // Start ImGui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); // Create a simple ImGui window ImGui::Begin("Hello, ImGui!"); ImGui::Text("If you can see this, everything is working!"); // Add a color editor just to test interactivity static ImVec4 color = ImVec4(0.4f, 0.7f, 0.0f, 1.0f); ImGui::ColorEdit3("Color", (float*)&color); ImGui::End(); // Rendering ImGui::Render(); int display_w, display_h; glfwGetFramebufferSize(window, &display_w, &display_h); glViewport(0, 0, display_w, display_h); glClearColor(color.x, color.y, color.z, color.w); glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); glfwSwapBuffers(window); } // Cleanup ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); glfwDestroyWindow(window); glfwTerminate(); return 0; }