From 97d7902f948cf0e01bea9c6b4dc607040047f469 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 19 Feb 2021 03:43:59 +0000 Subject: [PATCH] targets: Show implot demo --- src/xrt/targets/gui/gui_sdl2_imgui.c | 16 +++++++++++----- src/xrt/targets/openxr/oxr_sdl2_hack.c | 20 ++++++++++++++++---- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/xrt/targets/gui/gui_sdl2_imgui.c b/src/xrt/targets/gui/gui_sdl2_imgui.c index 2289be172..c7694387c 100644 --- a/src/xrt/targets/gui/gui_sdl2_imgui.c +++ b/src/xrt/targets/gui/gui_sdl2_imgui.c @@ -32,7 +32,8 @@ */ struct gui_imgui { - bool show_demo_window; + bool show_imgui_demo; + bool show_implot_demo; struct xrt_colour_rgb_f32 clear; }; @@ -49,7 +50,6 @@ gui_sdl2_imgui_loop(struct sdl2_program *p) // Need to call this before any other Imgui call. igCreateContext(NULL); - // Local state ImGuiIO *io = igGetIO(); @@ -71,7 +71,8 @@ gui_sdl2_imgui_loop(struct sdl2_program *p) gui.clear.b = 0.60f; u_var_add_root(&gui, "GUI Control", false); u_var_add_rgb_f32(&gui, &gui.clear, "Clear Colour"); - u_var_add_bool(&gui, &gui.show_demo_window, "Demo Window"); + u_var_add_bool(&gui, &gui.show_imgui_demo, "Imgui Demo Window"); + u_var_add_bool(&gui, &gui.show_implot_demo, "Implot Demo Window"); u_var_add_bool(&gui, &p->base.stopped, "Exit"); while (!p->base.stopped) { @@ -101,8 +102,13 @@ gui_sdl2_imgui_loop(struct sdl2_program *p) gui_scene_manager_render(&p->base); // Handle this here. - if (gui.show_demo_window) { - igShowDemoWindow(&gui.show_demo_window); + if (gui.show_imgui_demo) { + igShowDemoWindow(&gui.show_imgui_demo); + } + + // Handle this here. + if (gui.show_implot_demo) { + ImPlot_ShowDemoWindow(&gui.show_implot_demo); } // Build the DrawData (EndFrame). diff --git a/src/xrt/targets/openxr/oxr_sdl2_hack.c b/src/xrt/targets/openxr/oxr_sdl2_hack.c index 9996c38e3..54804ef58 100644 --- a/src/xrt/targets/openxr/oxr_sdl2_hack.c +++ b/src/xrt/targets/openxr/oxr_sdl2_hack.c @@ -64,7 +64,8 @@ struct sdl2_program struct gui_imgui { - bool show_demo_window; + bool show_imgui_demo; + bool show_implot_demo; struct xrt_colour_rgb_f32 clear; }; @@ -140,6 +141,10 @@ sdl2_loop(struct sdl2_program *p) // Setup Dear ImGui style igStyleColorsDark(NULL); + // Setup the plot context. + ImPlotContext *plot_ctx = ImPlot_CreateContext(); + ImPlot_SetCurrentContext(plot_ctx); + // Main loop struct gui_imgui gui = {0}; gui.clear.r = 0.45f; @@ -147,7 +152,8 @@ sdl2_loop(struct sdl2_program *p) gui.clear.b = 0.60f; u_var_add_root(&gui, "GUI Control", false); u_var_add_rgb_f32(&gui, &gui.clear, "Clear Colour"); - u_var_add_bool(&gui, &gui.show_demo_window, "Demo Window"); + u_var_add_bool(&gui, &gui.show_imgui_demo, "Imgui Demo Window"); + u_var_add_bool(&gui, &gui.show_implot_demo, "Implot Demo Window"); u_var_add_bool(&gui, &p->base.stopped, "Exit"); while (!p->base.stopped) { @@ -177,8 +183,13 @@ sdl2_loop(struct sdl2_program *p) gui_scene_manager_render(&p->base); // Handle this here. - if (gui.show_demo_window) { - igShowDemoWindow(&gui.show_demo_window); + if (gui.show_imgui_demo) { + igShowDemoWindow(&gui.show_imgui_demo); + } + + // Handle this here. + if (gui.show_implot_demo) { + ImPlot_ShowDemoWindow(&gui.show_implot_demo); } // Build the DrawData (EndFrame). @@ -198,6 +209,7 @@ sdl2_loop(struct sdl2_program *p) // Cleanup u_var_remove_root(&gui); + ImPlot_DestroyContext(plot_ctx); igImGui_ImplOpenGL3_Shutdown(); igImGui_ImplSDL2_Shutdown(); igDestroyContext(NULL);