forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugGUI.cxx
More file actions
85 lines (75 loc) · 2.59 KB
/
DebugGUI.cxx
File metadata and controls
85 lines (75 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#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 <GLFW/glfw3.h>
#include <cstdio>
#include <functional>
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, nullptr, nullptr);
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, nullptr, io.Fonts->GetGlyphRangesJapanese());
return window;
}
/// @return true if we do not need to exit, false if we do.
bool pollGUI(void* context, std::function<void(void)> guiCallback)
{
GLFWwindow* window = reinterpret_cast<GLFWwindow*>(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