diff --git a/common/ux-alignment.cpp b/common/ux-alignment.cpp index 5f5acbf4fd..7d66c9d76a 100644 --- a/common/ux-alignment.cpp +++ b/common/ux-alignment.cpp @@ -4,6 +4,7 @@ #include "ux-alignment.h" #include #include +#include #include #include @@ -49,8 +50,7 @@ bool is_gui_aligned(GLFWwindow *win) glfwSwapBuffers(win); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + ImGui::PushNewFrame(); SetFocus(hwn); diff --git a/common/ux-window.cpp b/common/ux-window.cpp index b4128c7bbf..98c0d0eb74 100644 --- a/common/ux-window.cpp +++ b/common/ux-window.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "device-model.h" @@ -222,9 +223,7 @@ namespace rs2 if (_use_glsl_proc) rs2::gl::shutdown_processing(); ImGui::GetIO().Fonts->ClearFonts(); // To be refactored into Viewer theme object - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); + ImGui::PopNewFrame(); glfwDestroyWindow(_win); glfwDestroyCursor(_hand_cursor); glfwDestroyCursor(_cross_cursor); @@ -671,7 +670,7 @@ namespace rs2 } ImGui::GetIO().Fonts->ClearFonts(); // To be refactored into Viewer theme object - ImGui_ImplGlfw_Shutdown(); + ImGui::PopNewFrame(); glfwDestroyWindow(_win); glfwDestroyCursor(_hand_cursor); @@ -757,9 +756,7 @@ namespace rs2 ImGui::GetIO().MouseWheel = _mouse.ui_wheel; _mouse.ui_wheel = 0.f; - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + ImGui::PushNewFrame(); } void ux_window::begin_viewport() diff --git a/examples/align-advanced/rs-align-advanced.cpp b/examples/align-advanced/rs-align-advanced.cpp index 9be310847f..93c3676c84 100644 --- a/examples/align-advanced/rs-align-advanced.cpp +++ b/examples/align-advanced/rs-align-advanced.cpp @@ -116,18 +116,14 @@ int main(int argc, char * argv[]) try renderer.show(pip_stream); // Using ImGui library to provide a slide controller to select the depth clipping distance - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + ImGui::PushNewFrame(); render_slider({ 5.f, 0, w, h }, depth_clipping_distance); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } // Cleanup - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); + ImGui::PopNewFrame(); return EXIT_SUCCESS; } catch (const rs2::error & e) diff --git a/examples/align-gl/rs-align-gl.cpp b/examples/align-gl/rs-align-gl.cpp index b966b3187a..f1ec223432 100644 --- a/examples/align-gl/rs-align-gl.cpp +++ b/examples/align-gl/rs-align-gl.cpp @@ -130,17 +130,12 @@ int main(int argc, char * argv[]) try glDisable(GL_BLEND); // Render the UI: - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + ImGui::PushNewFrame(); render_slider({ 15.f, app.height() - 60, app.width() - 30, app.height() }, &alpha, &dir); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } - // Cleanup - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); + ImGui::PopNewFrame(); return EXIT_SUCCESS; } catch (const rs2::error & e) diff --git a/examples/align/rs-align.cpp b/examples/align/rs-align.cpp index 2126906edc..e6b05b3480 100644 --- a/examples/align/rs-align.cpp +++ b/examples/align/rs-align.cpp @@ -119,17 +119,12 @@ int main(int argc, char * argv[]) try glDisable(GL_BLEND); // Render the UI: - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + ImGui::PushNewFrame(); render_slider({ 15.f, app.height() - 60, app.width() - 30, app.height() }, &alpha, &dir); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } - // Cleanup - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); + ImGui::PopNewFrame(); return EXIT_SUCCESS; } catch (const rs2::error & e) diff --git a/examples/example-imgui.hpp b/examples/example-imgui.hpp index 862a00792f..69d2581edd 100644 --- a/examples/example-imgui.hpp +++ b/examples/example-imgui.hpp @@ -10,6 +10,7 @@ #include "example.hpp" #include #include +#include ////////////////////////////// @@ -163,9 +164,6 @@ class hdr_widgets { //we need slider 2 to be showen before slider 1 (otherwise slider 1 padding is covering slider 2) void render_widgets() { - //start a new frame of ImGui - ImGui_ImplGlfw_NewFrame(); - _exposure_slider_seq_2.show(); _exposure_slider_seq_1.show(); _gain_slider_seq_2.show(); @@ -183,7 +181,7 @@ class hdr_widgets { //render the ImGui features: sliders and text ImGui::Render(); - + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } // return a reference to frames map diff --git a/examples/hdr/rs-hdr.cpp b/examples/hdr/rs-hdr.cpp index caf61e7387..e13582659b 100644 --- a/examples/hdr/rs-hdr.cpp +++ b/examples/hdr/rs-hdr.cpp @@ -150,21 +150,14 @@ int main() try //update frames in frames map in hdr_widgets hdr_widgets.update_frames_map(infrared_frame, depth_frame, hdr_frame, hdr_seq_id, hdr_seq_size); - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + ImGui::PushNewFrame(); //render hdr widgets sliders and text boxes hdr_widgets.render_widgets(); //the show method, when applied on frame map, break it to frames and upload each frame into its specific tile app.show(hdr_widgets.get_frames_map()); - ImGui::Render(); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } - // Cleanup - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); + ImGui::PopNewFrame(); return EXIT_SUCCESS; } catch (const rs2::error& e) diff --git a/examples/post-processing/rs-post-processing.cpp b/examples/post-processing/rs-post-processing.cpp index fa063aa540..408111650c 100644 --- a/examples/post-processing/rs-post-processing.cpp +++ b/examples/post-processing/rs-post-processing.cpp @@ -226,10 +226,7 @@ int main(int argc, char * argv[]) try // (Not the safest way to join a thread, please wrap your threads in some RAII manner) stopped = true; processing_thread.join(); - // Cleanup - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); + ImGui::PopNewFrame(); return EXIT_SUCCESS; } catch (const rs2::error & e) @@ -265,9 +262,7 @@ void render_ui(float w, float h, std::vector& filters) | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + ImGui::PushNewFrame(); ImGui::SetNextWindowSize({ w, h }); ImGui::GetStyle().Colors[ImGuiCol_FrameBg] = ImVec4(0.2f, 0.2f, 0.2f, 1.0f); ImGui::GetStyle().Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.3f, 0.3f, 0.3f, 1.0f); diff --git a/examples/record-playback/rs-record-playback.cpp b/examples/record-playback/rs-record-playback.cpp index be20799fbf..ad3b6cd4a8 100644 --- a/examples/record-playback/rs-record-playback.cpp +++ b/examples/record-playback/rs-record-playback.cpp @@ -68,9 +68,7 @@ int main(int argc, char * argv[]) try | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + ImGui::PushNewFrame(); ImGui::SetNextWindowPos(ImVec2(0, 0)); ImGui::SetNextWindowSize({ app.width(), app.height() }); ImGui::Begin("app", nullptr, flags); @@ -208,9 +206,7 @@ int main(int argc, char * argv[]) try depth_image.render(depth, { app.width() * 0.25f, app.height() * 0.25f, app.width() * 0.5f, app.height() * 0.75f }); } // Cleanup - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); + ImGui::PopNewFrame(); return EXIT_SUCCESS; } catch (const rs2::error & e) diff --git a/third-party/imgui/realsense_imgui.cpp b/third-party/imgui/realsense_imgui.cpp index c46a91cc45..92ecb65184 100644 --- a/third-party/imgui/realsense_imgui.cpp +++ b/third-party/imgui/realsense_imgui.cpp @@ -1,8 +1,10 @@ /* License: Apache 2.0. See LICENSE file in root directory. */ /* Copyright(c) 2024 Intel Corporation. All Rights Reserved. */ -//Overloading imgui functions to accommodate realsense GUI +//Overloading and adding on imgui functions to accommodate realsense GUI #include "realsense_imgui.h" +#include "imgui_impl_glfw.h" +#include "imgui_impl_opengl3.h" bool ImGui::SliderIntWithSteps(const char* label, int* v, int v_min, int v_max, int v_step) { @@ -69,7 +71,7 @@ bool Items_SingleStringGetter(void* data, int idx, const char** out_text) return true; } -IMGUI_API bool ImGui::CustomComboBox(const char* label, int* current_item, const char* const items[], int items_count) +bool ImGui::CustomComboBox(const char* label, int* current_item, const char* const items[], int items_count) { bool value_changed = false; @@ -116,7 +118,7 @@ IMGUI_API bool ImGui::CustomComboBox(const char* label, int* current_item, const return value_changed; } -IMGUI_API bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags, bool render_bg) +bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags, bool render_bg) { ImGuiContext& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); @@ -358,3 +360,19 @@ bool ImGui::SliderIntTofloat(const char* label, int* v, int v_min, int v_max, co *v = (int)v_f; return value_changed; } + +void ImGui::PushNewFrame() +{ + // Start the Dear ImGui frame + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); +} + +void ImGui::PopNewFrame() +{ + // Cleanup + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); +} diff --git a/third-party/imgui/realsense_imgui.h b/third-party/imgui/realsense_imgui.h index bb9cd09d1b..b77a8b5c11 100644 --- a/third-party/imgui/realsense_imgui.h +++ b/third-party/imgui/realsense_imgui.h @@ -32,6 +32,8 @@ namespace ImGui IMGUI_API bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags, bool render_bg); IMGUI_API bool VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power, bool render_bg); IMGUI_API bool SliderIntTofloat(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f"); + IMGUI_API void PushNewFrame(); + IMGUI_API void PopNewFrame(); } #define CONCAT_(x,y) x##y diff --git a/tools/realsense-viewer/realsense-viewer.cpp b/tools/realsense-viewer/realsense-viewer.cpp index e3abfbafe4..1bc1a9eac1 100644 --- a/tools/realsense-viewer/realsense-viewer.cpp +++ b/tools/realsense-viewer/realsense-viewer.cpp @@ -662,8 +662,6 @@ int main(int argc, const char** argv) try } } - ImGui::SetNextWindowContentSize(ImVec2(windows_width, 0.0f)); - auto pos = ImGui::GetCursorScreenPos(); auto h = ImGui::GetWindowHeight(); if (h > pos.y - viewer_model.panel_y) diff --git a/tools/rosbag-inspector/rs-rosbag-inspector.cpp b/tools/rosbag-inspector/rs-rosbag-inspector.cpp index 2558f8b781..b4a2026b31 100644 --- a/tools/rosbag-inspector/rs-rosbag-inspector.cpp +++ b/tools/rosbag-inspector/rs-rosbag-inspector.cpp @@ -27,6 +27,7 @@ #include #include "imgui_impl_opengl3.h" #include +#include #ifdef _MSC_VER #ifndef NOMINMAX #define NOMINMAX @@ -69,9 +70,7 @@ class gui_window glfwGetWindowSize(_window, &_w, &_h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + ImGui::PushNewFrame(); _first_frame = false; return res; } @@ -442,9 +441,7 @@ int main(int argc, const char** argv) try std::this_thread::sleep_for(std::chrono::milliseconds(10)); } // Cleanup - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); + ImGui::PopNewFrame(); glfwTerminate(); return 0; }