#include "imgui.h" #include "imgui_impl_glfw_gl3.h" #include "GL/gl3w.h" // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you. #include #include #include static void error_callback(int error, const char* description) { fprintf(stderr, "Error %d: %s\n", error, description); } namespace o2 { namespace framework { // @return an object of kind GLFWwindow* as void* to avoid having a direct dependency void* initGUI(const char* name) { // Setup window glfwSetErrorCallback(error_callback); if (!glfwInit()) return nullptr; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #if __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #endif GLFWwindow* window = glfwCreateWindow(1280, 720, name, NULL, NULL); glfwMakeContextCurrent(window); gl3wInit(); // Setup ImGui binding ImGui_ImplGlfwGL3_Init(window, true); // Load Fonts // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details) // ImGuiIO& io = ImGui::GetIO(); // io.Fonts->AddFontDefault(); // io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); // io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f); // io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f); // io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); // io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); return window; } /// @return true if we do not need to exit, false if we do. bool pollGUI(void* context, std::function guiCallback) { GLFWwindow* window = reinterpret_cast(context); if (glfwWindowShouldClose(window)) { return false; } glfwPollEvents(); ImGui_ImplGlfwGL3_NewFrame(); // Rendering int display_w, display_h; glfwGetFramebufferSize(window, &display_w, &display_h); glViewport(0, 0, display_w, display_h); ImVec4 clear_color = ImColor(114, 144, 154); glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w); glClear(GL_COLOR_BUFFER_BIT); // This is where the magic actually happens... if (guiCallback) { guiCallback(); } ImGui::Render(); glfwSwapBuffers(window); return true; } void disposeGUI() { // Cleanup ImGui_ImplGlfwGL3_Shutdown(); glfwTerminate(); } } // namespace framework } // namespace o2