From 86d8f64debf3d9ca25ace69dd5c19a8ac6283ade Mon Sep 17 00:00:00 2001 From: Noy-Zini Date: Tue, 26 Nov 2024 11:28:20 +0200 Subject: [PATCH] add libdl for linux OpenGL3 --- common/device-model.cpp | 6 +- common/option-model.cpp | 4 +- common/stream-model.cpp | 2 +- common/subdevice-model.cpp | 12 +-- common/ux-alignment.cpp | 2 +- common/ux-window.cpp | 6 +- examples/CMakeLists.txt | 6 ++ examples/align-advanced/rs-align-advanced.cpp | 6 +- examples/align-gl/rs-align-gl.cpp | 4 +- examples/align/rs-align.cpp | 4 +- examples/hdr/rs-hdr.cpp | 4 +- .../post-processing/rs-post-processing.cpp | 6 +- .../record-playback/rs-record-playback.cpp | 4 +- third-party/imgui/realsense_imgui.cpp | 76 +++++++------------ third-party/imgui/realsense_imgui.h | 39 +++++----- tools/CMakeLists.txt | 6 ++ .../rosbag-inspector/rs-rosbag-inspector.cpp | 4 +- 17 files changed, 92 insertions(+), 99 deletions(-) diff --git a/common/device-model.cpp b/common/device-model.cpp index d0ca7eea159..db2d5a4e4f4 100644 --- a/common/device-model.cpp +++ b/common/device-model.cpp @@ -2001,7 +2001,7 @@ namespace rs2 try { - if (ImGui::CustomComboBox(opt_model.id.c_str(), &selected, labels.data(), + if (RsImGui::CustomComboBox(opt_model.id.c_str(), &selected, labels.data(), static_cast(labels.size()))) { *opt_model.invalidate_flag = true; @@ -2897,7 +2897,7 @@ namespace rs2 ImGui::PushStyleColor(ImGuiCol_Text, white); ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background); label = rsutils::string::from() << "Enable " << pb->get_name() << " post-processing filter"; - ImGui::SetTooltip(label.c_str()); + ImGui::SetTooltip("%s",label.c_str()); window.link_hovered(); ImGui::PopStyleColor(2); } @@ -2922,7 +2922,7 @@ namespace rs2 ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background); label = rsutils::string::from() << "Disable " << pb->get_name() << " post-processing filter"; - ImGui::SetTooltip(label.c_str()); + ImGui::SetTooltip("%s",label.c_str()); window.link_hovered(); ImGui::PopStyleColor(2); } diff --git a/common/option-model.cpp b/common/option-model.cpp index cebc5bf0bc3..1c3d0734166 100644 --- a/common/option-model.cpp +++ b/common/option-model.cpp @@ -265,7 +265,7 @@ bool option_model::draw_combobox( notifications_model & model, try { - if( ImGui::CustomComboBox( id.c_str(), &selected, labels.data(), static_cast< int >( labels.size() ) ) ) + if( RsImGui::CustomComboBox( id.c_str(), &selected, labels.data(), static_cast< int >( labels.size() ) ) ) { float tmp_value = range.min + range.step * selected; model.add_log( rsutils::string::from() @@ -497,7 +497,7 @@ bool option_model::draw_slider( notifications_model & model, // runs when changing a value with slider and not the textbox auto int_value = static_cast< int >( value_as_float() ); - if( ImGui::SliderIntWithSteps( id.c_str(), + if( RsImGui::SliderIntWithSteps( id.c_str(), &int_value, static_cast< int >( range.min ), static_cast< int >( range.max ), diff --git a/common/stream-model.cpp b/common/stream-model.cpp index 4281bfe3d4a..2259ea17ffc 100644 --- a/common/stream-model.cpp +++ b/common/stream-model.cpp @@ -367,7 +367,7 @@ namespace rs2 bool draw_combo_box(const std::string& id, const std::vector& device_names, int& new_index) { std::vector device_names_chars = get_string_pointers(device_names); - return ImGui::CustomComboBox(id.c_str(), &new_index, device_names_chars.data(), static_cast(device_names.size())); + return RsImGui::CustomComboBox(id.c_str(), &new_index, device_names_chars.data(), static_cast(device_names.size())); } void stream_model::show_stream_header(ImFont* font, const rect &stream_rect, viewer_model& viewer) diff --git a/common/subdevice-model.cpp b/common/subdevice-model.cpp index 2b459628b44..833b450c1d3 100644 --- a/common/subdevice-model.cpp +++ b/common/subdevice-model.cpp @@ -563,7 +563,7 @@ namespace rs2 ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); auto tmp_selected_res_id = ui.selected_res_id; - if (ImGui::CustomComboBox(label.c_str(), &tmp_selected_res_id, res_chars.data(), + if (RsImGui::CustomComboBox(label.c_str(), &tmp_selected_res_id, res_chars.data(), static_cast(res_chars.size()))) { res = true; @@ -641,7 +641,7 @@ namespace rs2 { ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); - if (ImGui::CustomComboBox(label.c_str(), &ui.selected_shared_fps_id, fps_chars.data(), + if (RsImGui::CustomComboBox(label.c_str(), &ui.selected_shared_fps_id, fps_chars.data(), static_cast(fps_chars.size()))) { res = true; @@ -720,7 +720,7 @@ namespace rs2 { ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); - ImGui::CustomComboBox(label.c_str(), &ui.selected_format_id[f.first], formats_chars.data(), + RsImGui::CustomComboBox(label.c_str(), &ui.selected_format_id[f.first], formats_chars.data(), static_cast(formats_chars.size())); ImGui::PopStyleColor(); ImGui::PopItemWidth(); @@ -747,7 +747,7 @@ namespace rs2 { ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); - ImGui::CustomComboBox(label.c_str(), &ui.selected_fps_id[f.first], fps_chars.data(), + RsImGui::CustomComboBox(label.c_str(), &ui.selected_fps_id[f.first], fps_chars.data(), static_cast(fps_chars.size())); ImGui::PopStyleColor(); ImGui::PopItemWidth(); @@ -803,7 +803,7 @@ namespace rs2 ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); auto tmp_selected_res_id = ui.selected_res_id_map[stream_type_id]; - if (ImGui::CustomComboBox(label.c_str(), &tmp_selected_res_id, res_chars.data(), + if (RsImGui::CustomComboBox(label.c_str(), &tmp_selected_res_id, res_chars.data(), static_cast(res_chars.size()))) { res = true; @@ -935,7 +935,7 @@ namespace rs2 { ImGui::PushItemWidth(-1); // Set the width for the combo box itself ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, { 1,1,1,1 }); - ImGui::CustomComboBox(label.c_str(), &ui.selected_format_id[f.first], formats_chars.data(), + RsImGui::CustomComboBox(label.c_str(), &ui.selected_format_id[f.first], formats_chars.data(), static_cast(formats_chars.size())); ImGui::PopStyleColor(); ImGui::PopItemWidth(); diff --git a/common/ux-alignment.cpp b/common/ux-alignment.cpp index 7d66c9d76a8..0744eb6e1f1 100644 --- a/common/ux-alignment.cpp +++ b/common/ux-alignment.cpp @@ -50,7 +50,7 @@ bool is_gui_aligned(GLFWwindow *win) glfwSwapBuffers(win); - ImGui::PushNewFrame(); + RsImGui::PushNewFrame(); SetFocus(hwn); diff --git a/common/ux-window.cpp b/common/ux-window.cpp index 98c0d0eb74b..95a16e6dec8 100644 --- a/common/ux-window.cpp +++ b/common/ux-window.cpp @@ -223,7 +223,7 @@ namespace rs2 if (_use_glsl_proc) rs2::gl::shutdown_processing(); ImGui::GetIO().Fonts->ClearFonts(); // To be refactored into Viewer theme object - ImGui::PopNewFrame(); + RsImGui::PopNewFrame(); glfwDestroyWindow(_win); glfwDestroyCursor(_hand_cursor); glfwDestroyCursor(_cross_cursor); @@ -670,7 +670,7 @@ namespace rs2 } ImGui::GetIO().Fonts->ClearFonts(); // To be refactored into Viewer theme object - ImGui::PopNewFrame(); + RsImGui::PopNewFrame(); glfwDestroyWindow(_win); glfwDestroyCursor(_hand_cursor); @@ -756,7 +756,7 @@ namespace rs2 ImGui::GetIO().MouseWheel = _mouse.ui_wheel; _mouse.ui_wheel = 0.f; - ImGui::PushNewFrame(); + RsImGui::PushNewFrame(); } void ux_window::begin_viewport() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 5be323b74b5..673fa205575 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -18,6 +18,12 @@ else() list( APPEND DEPENDENCIES log ) endif() endif() +# Check the platform and conditionally link OpenGL and libdl (for linux) +if(WIN32) + list( APPEND DEPENDENCIES OpenGL::GL) +else() + list( APPEND DEPENDENCIES OpenGL::GL dl) +endif() # Add all imgui cpp source files and store the list in the IMGUI_SOURCES variable file(GLOB IMGUI_SOURCES "../third-party/imgui/*.cpp") diff --git a/examples/align-advanced/rs-align-advanced.cpp b/examples/align-advanced/rs-align-advanced.cpp index 93c3676c84b..057eeb03973 100644 --- a/examples/align-advanced/rs-align-advanced.cpp +++ b/examples/align-advanced/rs-align-advanced.cpp @@ -116,14 +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::PushNewFrame(); + RsImGui::PushNewFrame(); render_slider({ 5.f, 0, w, h }, depth_clipping_distance); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } // Cleanup - ImGui::PopNewFrame(); + RsImGui::PopNewFrame(); return EXIT_SUCCESS; } catch (const rs2::error & e) @@ -172,7 +172,7 @@ void render_slider(rect location, float& clipping_dist) ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255).Value); ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255).Value); auto slider_size = ImVec2(slider_window_width / 2, location.h - (pixels_to_buttom_of_stream_text * 2) - 20); - ImGui::VSliderFloat("##vslider", slider_size, &clipping_dist, 0.0f, 6.0f, "", 1.0f, true); + RsImGui::VSliderFloat("##vslider", slider_size, &clipping_dist, 0.0f, 6.0f, "", 1.0f, true); if (ImGui::IsItemHovered()) ImGui::SetTooltip("Depth Clipping Distance: %.3f", clipping_dist); ImGui::PopStyleColor(3); diff --git a/examples/align-gl/rs-align-gl.cpp b/examples/align-gl/rs-align-gl.cpp index f1ec2234325..f3b364967d1 100644 --- a/examples/align-gl/rs-align-gl.cpp +++ b/examples/align-gl/rs-align-gl.cpp @@ -130,12 +130,12 @@ int main(int argc, char * argv[]) try glDisable(GL_BLEND); // Render the UI: - ImGui::PushNewFrame(); + RsImGui::PushNewFrame(); render_slider({ 15.f, app.height() - 60, app.width() - 30, app.height() }, &alpha, &dir); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } - ImGui::PopNewFrame(); + RsImGui::PopNewFrame(); return EXIT_SUCCESS; } catch (const rs2::error & e) diff --git a/examples/align/rs-align.cpp b/examples/align/rs-align.cpp index e6b05b3480f..5756782e629 100644 --- a/examples/align/rs-align.cpp +++ b/examples/align/rs-align.cpp @@ -119,12 +119,12 @@ int main(int argc, char * argv[]) try glDisable(GL_BLEND); // Render the UI: - ImGui::PushNewFrame(); + RsImGui::PushNewFrame(); render_slider({ 15.f, app.height() - 60, app.width() - 30, app.height() }, &alpha, &dir); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } - ImGui::PopNewFrame(); + RsImGui::PopNewFrame(); return EXIT_SUCCESS; } catch (const rs2::error & e) diff --git a/examples/hdr/rs-hdr.cpp b/examples/hdr/rs-hdr.cpp index e13582659b1..0133ccca2d6 100644 --- a/examples/hdr/rs-hdr.cpp +++ b/examples/hdr/rs-hdr.cpp @@ -150,14 +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::PushNewFrame(); + RsImGui::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::PopNewFrame(); + RsImGui::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 408111650cf..cbd75ad52f2 100644 --- a/examples/post-processing/rs-post-processing.cpp +++ b/examples/post-processing/rs-post-processing.cpp @@ -226,7 +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(); - ImGui::PopNewFrame(); + RsImGui::PopNewFrame(); return EXIT_SUCCESS; } catch (const rs2::error & e) @@ -262,7 +262,7 @@ void render_ui(float w, float h, std::vector& filters) | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; - ImGui::PushNewFrame(); + RsImGui::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); @@ -331,7 +331,7 @@ bool filter_slider_ui::render(const float3& location, bool enabled) if (is_int) { int value_as_int = static_cast(value); - value_changed = ImGui::SliderIntTofloat(("##" + name).c_str(), &value_as_int, static_cast(range.min), static_cast(range.max), "%.0f"); + value_changed = RsImGui::SliderIntTofloat(("##" + name).c_str(), &value_as_int, static_cast(range.min), static_cast(range.max), "%.0f"); if( step > 1 ) { value_as_int = static_cast< int >( range.min ) diff --git a/examples/record-playback/rs-record-playback.cpp b/examples/record-playback/rs-record-playback.cpp index ad3b6cd4a82..6263ef04e7d 100644 --- a/examples/record-playback/rs-record-playback.cpp +++ b/examples/record-playback/rs-record-playback.cpp @@ -68,7 +68,7 @@ int main(int argc, char * argv[]) try | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; - ImGui::PushNewFrame(); + RsImGui::PushNewFrame(); ImGui::SetNextWindowPos(ImVec2(0, 0)); ImGui::SetNextWindowSize({ app.width(), app.height() }); ImGui::Begin("app", nullptr, flags); @@ -206,7 +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::PopNewFrame(); + RsImGui::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 92ecb651842..20edf44a000 100644 --- a/third-party/imgui/realsense_imgui.cpp +++ b/third-party/imgui/realsense_imgui.cpp @@ -6,7 +6,7 @@ #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) +bool RsImGui::SliderIntWithSteps(const char* label, int* v, int v_min, int v_max, int v_step) { float originalValue = *v; bool changed = false; @@ -34,7 +34,7 @@ bool ImGui::SliderIntWithSteps(const char* label, int* v, int v_min, int v_max, return changed && (*v != originalValue); } -float ImGui::RoundScalar(float value, int decimal_precision) +float RsImGui::RoundScalar(float value, int decimal_precision) { // Round past decimal precision // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0 @@ -51,27 +51,7 @@ float ImGui::RoundScalar(float value, int decimal_precision) return negative ? -value : value; } -bool Items_SingleStringGetter(void* data, int idx, const char** out_text) -{ - // FIXME-OPT: we could pre-compute the indices to fasten this. But only 1 active combo means the waste is limited. - const char* items_separated_by_zeros = (const char*)data; - int items_count = 0; - const char* p = items_separated_by_zeros; - while (*p) - { - if (idx == items_count) - break; - p += strlen(p) + 1; - items_count++; - } - if (!*p) - return false; - if (out_text) - *out_text = p; - return true; -} - -bool ImGui::CustomComboBox(const char* label, int* current_item, const char* const items[], int items_count) +bool RsImGui::CustomComboBox(const char* label, int* current_item, const char* const items[], int items_count) { bool value_changed = false; @@ -118,10 +98,10 @@ bool ImGui::CustomComboBox(const char* label, int* current_item, const char* con return value_changed; } -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 RsImGui::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(); + ImGuiWindow* window = ImGui::GetCurrentWindow(); const ImGuiStyle& style = g.Style; const bool is_non_linear = fabsf(power - 1.0f) > 0.0001f; @@ -131,7 +111,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v if (!render_bg) { // Draw frame - RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); + ImGui::RenderFrame(frame_bb.Min, frame_bb.Max, ImGui::GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); } @@ -202,7 +182,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v } // Round past decimal precision, verify that it remains within min/max range - new_value = RoundScalar(new_value, decimal_precision); + new_value = RsImGui::RoundScalar(new_value, decimal_precision); if (new_value > v_max) new_value = v_max; if (new_value < v_min) new_value = v_min; @@ -214,7 +194,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v } else { - ClearActiveID(); + ImGui::ClearActiveID(); } } @@ -293,21 +273,21 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v radius = width;// / 2.5; } // Draw frame - RenderFrame(bb.Min, bb.Max, GetColorU32(ImGuiCol_FrameBg), false, 10.0f); - RenderFrame(fill_br.Min, fill_br.Max, ImGui::ColorConvertFloat4ToU32({ 0, 112.f / 255, 197.f / 255, 1 }), false, 10.0f); - window->DrawList->AddCircleFilled(graber_size, radius, GetColorU32(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), 16); + ImGui::RenderFrame(bb.Min, bb.Max, ImGui::GetColorU32(ImGuiCol_FrameBg), false, 10.0f); + ImGui::RenderFrame(fill_br.Min, fill_br.Max, ImGui::ColorConvertFloat4ToU32({ 0, 112.f / 255, 197.f / 255, 1 }), false, 10.0f); + window->DrawList->AddCircleFilled(graber_size, radius, ImGui::GetColorU32(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), 16); } else { - window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, GetColorU32(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), style.GrabRounding); + window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, ImGui::GetColorU32(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab), style.GrabRounding); } return value_changed; } -bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power, bool render_bg) +bool RsImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power, bool render_bg) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiWindow* window = ImGui::GetCurrentWindow(); if (window->SkipItems) return false; @@ -315,17 +295,17 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); - const ImVec2 label_size = CalcTextSize(label, NULL, true); + const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); const ImRect frame_bb(window->DC.CursorPos, ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y + size.y)); const ImRect bb(frame_bb.Min,ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x + frame_bb.Max .x: frame_bb.Max.x, frame_bb.Max.y)); - ItemSize(bb, style.FramePadding.y); - if (!ItemAdd(frame_bb, id)) + ImGui::ItemSize(bb, style.FramePadding.y); + if (!ImGui::ItemAdd(frame_bb, id)) return false; - const bool hovered = IsItemHovered(); + const bool hovered = ImGui::IsItemHovered(); if (hovered) - SetHoveredID(id); + ImGui::SetHoveredID(id); if (!display_format) display_format = "%.3f"; @@ -333,35 +313,35 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float if (hovered && g.IO.MouseClicked[0]) { - SetActiveID(id, window); - FocusWindow(window); + ImGui::SetActiveID(id, window); + ImGui::FocusWindow(window); } // Actual slider behavior + render grab - bool value_changed = SliderBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision, ImGuiSliderFlags_Vertical, render_bg); + bool value_changed = RsImGui::SliderBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision, ImGuiSliderFlags_Vertical, render_bg); // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. // For the vertical slider we allow centered text to overlap the frame padding char value_buf[64]; char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); - RenderTextClipped(ImVec2(frame_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), frame_bb.Max, value_buf, value_buf_end, NULL); + ImGui::RenderTextClipped(ImVec2(frame_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), frame_bb.Max, value_buf, value_buf_end, NULL); if (label_size.x > 0.0f) - RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + ImGui::RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); return value_changed; } -bool ImGui::SliderIntTofloat(const char* label, int* v, int v_min, int v_max, const char* display_format) +bool RsImGui::SliderIntTofloat(const char* label, int* v, int v_min, int v_max, const char* display_format) { if (!display_format) display_format = "%.0f"; float v_f = (float)*v; - bool value_changed = SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f); + bool value_changed = ImGui::SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f); *v = (int)v_f; return value_changed; } -void ImGui::PushNewFrame() +void RsImGui::PushNewFrame() { // Start the Dear ImGui frame ImGui_ImplOpenGL3_NewFrame(); @@ -369,7 +349,7 @@ void ImGui::PushNewFrame() ImGui::NewFrame(); } -void ImGui::PopNewFrame() +void RsImGui::PopNewFrame() { // Cleanup ImGui_ImplOpenGL3_Shutdown(); diff --git a/third-party/imgui/realsense_imgui.h b/third-party/imgui/realsense_imgui.h index b77a8b5c112..9e74e55fc22 100644 --- a/third-party/imgui/realsense_imgui.h +++ b/third-party/imgui/realsense_imgui.h @@ -5,39 +5,40 @@ #include "imgui.h" #include "imgui_internal.h" -namespace ImGui +namespace RsImGui { class ScopePushFont { public: - ScopePushFont(ImFont* font) { PushFont(font); } - ~ScopePushFont() { PopFont(); } + ScopePushFont(ImFont* font) { ImGui::PushFont(font); } + ~ScopePushFont() { ImGui::PopFont(); } }; class ScopePushStyleColor { public: - ScopePushStyleColor(ImGuiCol idx, const ImVec4& col) { PushStyleColor(idx, col); } - ~ScopePushStyleColor() { PopStyleColor(); } + ScopePushStyleColor(ImGuiCol idx, const ImVec4& col) { ImGui::PushStyleColor(idx, col); } + ~ScopePushStyleColor() { ImGui::PopStyleColor(); } }; class ScopePushStyleVar { public: - ScopePushStyleVar(ImGuiStyleVar idx, float val) { PushStyleVar(idx, val); } - ScopePushStyleVar(ImGuiStyleVar idx, const ImVec2& val) { PushStyleVar(idx, val); } - ~ScopePushStyleVar() { PopStyleVar(); } + ScopePushStyleVar(ImGuiStyleVar idx, float val) { ImGui::PushStyleVar(idx, val); } + ScopePushStyleVar(ImGuiStyleVar idx, const ImVec2& val) { ImGui::PushStyleVar(idx, val); } + ~ScopePushStyleVar() { ImGui::PopStyleVar(); } }; - IMGUI_API bool SliderIntWithSteps(const char* label, int* v, int v_min, int v_max, int v_step = 1); - IMGUI_API float RoundScalar(float value, int decimal_precision); - IMGUI_API bool CustomComboBox(const char* label, int* current_item, const char* const items[], int items_count); - 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(); + bool SliderIntWithSteps(const char* label, int* v, int v_min, int v_max, int v_step = 1); + float RoundScalar(float value, int decimal_precision); + bool CustomComboBox(const char* label, int* current_item, const char* const items[], int items_count); + 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); + 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); + bool SliderIntTofloat(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f"); + void PushNewFrame(); + void PopNewFrame(); } + #define CONCAT_(x,y) x##y #define CONCAT(x,y) CONCAT_(x,y) -#define ImGui_ScopePushFont(f) ImGui::ScopePushFont CONCAT(scope_push_font, __LINE__) (f) -#define ImGui_ScopePushStyleColor(idx, col) ImGui::ScopePushStyleColor CONCAT(scope_push_style_color, __LINE__) (idx, col) -#define ImGui_ScopePushStyleVar(idx, val) ImGui::ScopePushStyleVar CONCAT(scope_push_style_var, __LINE__) (idx, val) \ No newline at end of file +#define ImGui_ScopePushFont(f) RsImGui::ScopePushFont CONCAT(scope_push_font, __LINE__) (f) +#define ImGui_ScopePushStyleColor(idx, col) RsImGui::ScopePushStyleColor CONCAT(scope_push_style_color, __LINE__) (idx, col) +#define ImGui_ScopePushStyleVar(idx, val) RsImGui::ScopePushStyleVar CONCAT(scope_push_style_var, __LINE__) (idx, val) \ No newline at end of file diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 67381264e5f..85c1243bcdd 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -12,6 +12,12 @@ set_security_flags_for_executable() # tools are executables so we want position list( APPEND DEPENDENCIES ${LRS_TARGET} tclap ) # Add all imgui cpp source files and store the list in the IMGUI_SOURCES variable file(GLOB IMGUI_SOURCES "../third-party/imgui/*.cpp") +# Check the platform and conditionally link OpenGL and libdl (for linux) +if(WIN32) + list( APPEND DEPENDENCIES OpenGL::GL) +else() + list( APPEND DEPENDENCIES OpenGL::GL dl) +endif() if(BUILD_TOOLS) add_subdirectory(convert) diff --git a/tools/rosbag-inspector/rs-rosbag-inspector.cpp b/tools/rosbag-inspector/rs-rosbag-inspector.cpp index b4a2026b313..9afc2493956 100644 --- a/tools/rosbag-inspector/rs-rosbag-inspector.cpp +++ b/tools/rosbag-inspector/rs-rosbag-inspector.cpp @@ -70,7 +70,7 @@ class gui_window glfwGetWindowSize(_window, &_w, &_h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - ImGui::PushNewFrame(); + RsImGui::PushNewFrame(); _first_frame = false; return res; } @@ -441,7 +441,7 @@ int main(int argc, const char** argv) try std::this_thread::sleep_for(std::chrono::milliseconds(10)); } // Cleanup - ImGui::PopNewFrame(); + RsImGui::PopNewFrame(); glfwTerminate(); return 0; }