Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 78 additions & 36 deletions DebugGUI/src/DebugGUI.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,50 @@ namespace framework
// @return an object of kind GLFWwindow* as void* to avoid having a direct dependency
void* initGUI(const char* name, void(*error_callback)(int, char const*description))
{
// Setup window
if (error_callback == nullptr) {
glfwSetErrorCallback(default_error_callback);
GLFWwindow* window = nullptr;
if (name) {
// Setup window
if (error_callback == nullptr) {
glfwSetErrorCallback(default_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
window = glfwCreateWindow(1280, 720, name, nullptr, nullptr);
glfwMakeContextCurrent(window);
gl3wInit();

// Setup ImGui binding
ImGui_ImplGlfwGL3_Init(window, true);
} else {
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
ImGui::StyleColorsDark();
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB;
io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN;
io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP;
io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN;
io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME;
io.KeyMap[ImGuiKey_End] = GLFW_KEY_END;
io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE;
io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE;
io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER;
io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE;
io.KeyMap[ImGuiKey_A] = GLFW_KEY_A;
io.KeyMap[ImGuiKey_C] = GLFW_KEY_C;
io.KeyMap[ImGuiKey_V] = GLFW_KEY_V;
io.KeyMap[ImGuiKey_X] = GLFW_KEY_X;
io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
}
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)
Expand All @@ -50,7 +76,13 @@ void* initGUI(const char* name, void(*error_callback)(int, char const*descriptio
static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true; icons_config.FontDataOwnedByAtlas = false;
io.Fonts->AddFontFromMemoryTTF((void*)s_iconsFontAwesomeTtf, sizeof(s_iconsFontAwesomeTtf), 12.0f, &icons_config, icons_ranges);


// this initializes the texture
if (io.Fonts->ConfigData.empty())
io.Fonts->AddFontDefault();
io.Fonts->Build();
io.DisplaySize = ImVec2(1280, 720);

ImPlot::CreateContext();
return window;
}
Expand Down Expand Up @@ -186,23 +218,31 @@ void getFrameRaw(void *data, void **raw_data, int *size)
*raw_data = local_data_base;
}

bool pollGUIPreRender(void* context)
bool pollGUIPreRender(void* context, float delta)
{
GLFWwindow* window = reinterpret_cast<GLFWwindow*>(context);
if (context) {
GLFWwindow* window = reinterpret_cast<GLFWwindow*>(context);

if (glfwWindowShouldClose(window)) {
return false;
if (glfwWindowShouldClose(window)) {
return false;
}
glfwPollEvents();
ImGui_ImplGlfwGL3_NewFrame();

// Clearing the viewport
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);
} else {
// Just initialize new frame
ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = delta;
ImGui::NewFrame();
}
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);

return true;
}
Expand All @@ -221,16 +261,18 @@ void *pollGUIRender(std::function<void(void)> guiCallback)

void pollGUIPostRender(void* context, void *draw_data)
{
GLFWwindow* window = reinterpret_cast<GLFWwindow*>(context);
if (context) {
GLFWwindow* window = reinterpret_cast<GLFWwindow*>(context);

ImGui_ImplGlfwGL3_RenderDrawLists((ImDrawData*)draw_data);
glfwSwapBuffers(window);
ImGui_ImplGlfwGL3_RenderDrawLists((ImDrawData*)draw_data);
glfwSwapBuffers(window);
}
}

/// @return true if we do not need to exit, false if we do.
bool pollGUI(void* context, std::function<void(void)> guiCallback)
{
if (!pollGUIPreRender(context)) {
if (!pollGUIPreRender(context, 1.0f/60.0f)) {
return false;
}
void *draw_data = pollGUIRender(guiCallback);
Expand Down
2 changes: 1 addition & 1 deletion DebugGUI/src/DebugGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void* initGUI(const char* name, decltype(default_error_callback) = nullptr);
bool pollGUI(void* context, std::function<void(void)> guiCallback);
void getFrameJSON(void *data, std::ostream& json_data);
void getFrameRaw(void *data, void **raw_data, int *size);
bool pollGUIPreRender(void* context);
bool pollGUIPreRender(void* context, float delta);
void* pollGUIRender(std::function<void(void)> guiCallback);
void pollGUIPostRender(void* context, void* draw_data);
void disposeGUI();
Expand Down
16 changes: 6 additions & 10 deletions DebugGUI/src/imgui_impl_glfw_gl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,15 @@ void ImGui_ImplGlfwGL3_NewFrame()
double mouse_x, mouse_y;
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
}
else
{
io.MousePos = ImVec2(-1,-1);
for (int i = 0; i < 3; i++)
{
io.MouseDown[i] = g_MousePressed[i] || glfwGetMouseButton(g_Window, i) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
g_MousePressed[i] = false;
}
io.MouseWheel = g_MouseWheel;
}

for (int i = 0; i < 3; i++)
{
io.MouseDown[i] = g_MousePressed[i] || glfwGetMouseButton(g_Window, i) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
g_MousePressed[i] = false;
}

io.MouseWheel = g_MouseWheel;
g_MouseWheel = 0.0f;

// Hide OS mouse cursor if ImGui is drawing it
Expand Down
13 changes: 13 additions & 0 deletions remote/dat.gui.min.js

Large diffs are not rendered by default.

Loading