The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

t/gui: Add imgui code

authored by

Jakob Bornecrantz and committed by
Jakob Bornecrantz
74bdb0cb 71b3de9c

+165
+18
src/xrt/targets/gui/CMakeLists.txt
··· 15 15 16 16 set(SOURCE_FILES 17 17 gui_common.h 18 + gui_imgui.c 19 + gui_imgui.h 18 20 gui_main.c 19 21 gui_ogl.c 20 22 gui_prober.c ··· 22 24 gui_sdl2.c 23 25 ../../../external/glad/gl.h 24 26 ../../../external/glad/gl.c 27 + ../../../external/imgui/cimgui.cpp 28 + ../../../external/imgui/cimgui.h 29 + ../../../external/imgui/imconfig.h 30 + ../../../external/imgui/imgui.cpp 31 + ../../../external/imgui/imgui.h 32 + ../../../external/imgui/imgui_demo.cpp 33 + ../../../external/imgui/imgui_draw.cpp 34 + ../../../external/imgui/imgui_impl_opengl3.cpp 35 + ../../../external/imgui/imgui_impl_opengl3.h 36 + ../../../external/imgui/imgui_impl_sdl.cpp 37 + ../../../external/imgui/imgui_impl_sdl.h 38 + ../../../external/imgui/imgui_internal.h 39 + ../../../external/imgui/imgui_widgets.cpp 40 + ../../../external/imgui/imstb_rectpack.h 41 + ../../../external/imgui/imstb_textedit.h 42 + ../../../external/imgui/imstb_truetype.h 25 43 ) 26 44 27 45 add_executable(gui
+8
src/xrt/targets/gui/gui_common.h
··· 95 95 gui_sdl2_init(struct program *p); 96 96 97 97 /*! 98 + * Loop until user request quit and show Imgui interface. 99 + * 100 + * @ingroup gui 101 + */ 102 + void 103 + gui_imgui_loop(struct program *p); 104 + 105 + /*! 98 106 * Loop until quit signal has been received. 99 107 * 100 108 * @ingroup gui
+125
src/xrt/targets/gui/gui_imgui.c
··· 1 + // Copyright 2019, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Main entrypoint for the Monado GUI program. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup gui 8 + */ 9 + 10 + #include "util/u_var.h" 11 + #include "util/u_time.h" 12 + #include "util/u_misc.h" 13 + #include "util/u_sink.h" 14 + #include "util/u_format.h" 15 + 16 + #include "xrt/xrt_prober.h" 17 + 18 + #include "gui_common.h" 19 + #include "gui_imgui.h" 20 + 21 + 22 + /* 23 + * 24 + * Structs and defines. 25 + * 26 + */ 27 + 28 + /*! 29 + * Internal gui state. 30 + * 31 + * @ingroup gui 32 + */ 33 + struct gui_imgui 34 + { 35 + bool show_demo_window; 36 + struct xrt_colour_rgb_f32 clear; 37 + }; 38 + 39 + 40 + /* 41 + * 42 + * 'Exported' functions. 43 + * 44 + */ 45 + 46 + void 47 + gui_imgui_loop(struct program *p) 48 + { 49 + // Need to call this before any other Imgui call. 50 + igCreateContext(NULL); 51 + 52 + // Local state 53 + ImGuiIO *io = igGetIO(); 54 + 55 + // Setup Platform/Renderer bindings 56 + igImGui_ImplSDL2_InitForOpenGL(p->win, p->ctx); 57 + igImGui_ImplOpenGL3_Init(NULL); 58 + 59 + // Setup Dear ImGui style 60 + igStyleColorsDark(NULL); 61 + 62 + // Main loop 63 + struct gui_imgui gui = {0}; 64 + gui.clear.r = 0.45f; 65 + gui.clear.g = 0.55f; 66 + gui.clear.b = 0.60f; 67 + u_var_add_root(&gui, "GUI Control", false); 68 + u_var_add_rgb_f32(&gui, &gui.clear, "Clear Colour"); 69 + u_var_add_bool(&gui, &gui.show_demo_window, "Demo Window"); 70 + u_var_add_bool(&gui, &p->stopped, "Exit"); 71 + 72 + while (!p->stopped) { 73 + SDL_Event event; 74 + 75 + while (SDL_PollEvent(&event)) { 76 + igImGui_ImplSDL2_ProcessEvent(&event); 77 + 78 + if (event.type == SDL_QUIT) { 79 + p->stopped = true; 80 + } 81 + 82 + if (event.type == SDL_WINDOWEVENT && 83 + event.window.event == SDL_WINDOWEVENT_CLOSE && 84 + event.window.windowID == SDL_GetWindowID(p->win)) { 85 + p->stopped = true; 86 + } 87 + } 88 + 89 + // Start the Dear ImGui frame 90 + igImGui_ImplOpenGL3_NewFrame(); 91 + igImGui_ImplSDL2_NewFrame(p->win); 92 + 93 + // Start new frame. 94 + igNewFrame(); 95 + 96 + // Render the scene into it. 97 + gui_scene_manager_render(p); 98 + 99 + // Handle this here. 100 + if (gui.show_demo_window) { 101 + igShowDemoWindow(&gui.show_demo_window); 102 + } 103 + 104 + // Build the DrawData (EndFrame). 105 + igRender(); 106 + 107 + // Clear the background. 108 + glViewport(0, 0, (int)io->DisplaySize.x, 109 + (int)io->DisplaySize.y); 110 + glClearColor(gui.clear.r, gui.clear.g, gui.clear.b, 1.0f); 111 + glClear(GL_COLOR_BUFFER_BIT); 112 + 113 + igImGui_ImplOpenGL3_RenderDrawData(igGetDrawData()); 114 + 115 + SDL_GL_SwapWindow(p->win); 116 + 117 + gui_prober_update(p); 118 + } 119 + 120 + // Cleanup 121 + u_var_remove_root(&gui); 122 + igImGui_ImplOpenGL3_Shutdown(); 123 + igImGui_ImplSDL2_Shutdown(); 124 + igDestroyContext(NULL); 125 + }
+14
src/xrt/targets/gui/gui_imgui.h
··· 1 + // Copyright 2019, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Imgui integration for gui. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup gui 8 + */ 9 + 10 + #pragma once 11 + 12 + #define CIMGUI_DEFINE_ENUMS_AND_STRUCTS 13 + #include "imgui/cimgui.h" 14 + #include "glad/gl.h"