From 1981309b7729f722cf52d8255d14111e3e958ef4 Mon Sep 17 00:00:00 2001 From: Rasmus Diederichsen Date: Fri, 29 Nov 2024 13:35:43 +0100 Subject: [PATCH 1/9] fix assimp linking and glm+assimp dependencies for installed project --- CMakeLists.txt | 2 +- cmake/iridescence-config.cmake.in | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0335153..e27d6ae6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,7 +95,7 @@ else() endif() if(${assimp_FOUND}) - list(APPEND EXTRA_LIBRARIES assimp) + list(APPEND EXTRA_LIBRARIES ${ASSIMP_LIBRARIES}) list(APPEND EXTRA_SOURCE src/glk/io/mesh_io.cpp) endif() diff --git a/cmake/iridescence-config.cmake.in b/cmake/iridescence-config.cmake.in index 18c04343..0aa1ca10 100644 --- a/cmake/iridescence-config.cmake.in +++ b/cmake/iridescence-config.cmake.in @@ -14,6 +14,8 @@ find_dependency(OpenGL REQUIRED) find_dependency(Eigen3 REQUIRED) find_dependency(PNG) find_dependency(JPEG) +find_dependency(glm) +find_dependency(assimp) include("${CMAKE_CURRENT_LIST_DIR}/iridescence-targets.cmake") add_library(Iridescence::Iridescence ALIAS Iridescence::iridescence) From 4c9401ffd1e4e9fa334d66051cd0c6d41d988567 Mon Sep 17 00:00:00 2001 From: Rasmus Diederichsen Date: Fri, 29 Nov 2024 13:35:49 +0100 Subject: [PATCH 2/9] Add missing include --- src/glk/pointcloud_buffer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/glk/pointcloud_buffer.cpp b/src/glk/pointcloud_buffer.cpp index 7951fb59..a7ace390 100644 --- a/src/glk/pointcloud_buffer.cpp +++ b/src/glk/pointcloud_buffer.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include From 10080aae9e3e53c8506e925d5ac9899763a44682 Mon Sep 17 00:00:00 2001 From: Rasmus Diederichsen Date: Fri, 29 Nov 2024 14:45:19 +0100 Subject: [PATCH 3/9] Fix glm FOUND variable --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e27d6ae6..8a65cd6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ find_package(JPEG) find_package(assimp QUIET) -if(NOT glm_FOUND) +if(NOT GLM_FOUND) message(STATUS "System GLM not found. Download GLM 1.0.1.") include(FetchContent) FetchContent_Populate( From bc26ae1524ef72257b9fb9ec6bbadfa5c1ea2982 Mon Sep 17 00:00:00 2001 From: Rasmus Diederichsen Date: Sun, 1 Dec 2024 19:12:49 +0100 Subject: [PATCH 4/9] Add missing install of gl3w files --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a65cd6b..3086883e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) endif() set(CMAKE_CXX_STANDARD 17) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake") +# list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") set(OpenGL_GL_PREFERENCE GLVND) if(BUILD_WITH_MARCH_NATIVE) @@ -26,7 +26,7 @@ endif() find_package(OpenGL REQUIRED) -find_package(glm) +find_package(glm 1.0.1 CONFIG REQUIRED) find_package(glfw3) find_package(Eigen3) find_package(PNG) @@ -34,7 +34,7 @@ find_package(JPEG) find_package(assimp QUIET) -if(NOT GLM_FOUND) +if(NOT glm_FOUND) message(STATUS "System GLM not found. Download GLM 1.0.1.") include(FetchContent) FetchContent_Populate( @@ -296,6 +296,7 @@ endif() install(DIRECTORY include/ DESTINATION ${INCLUDE_INSTALL_DIR}) install(DIRECTORY thirdparty/gl3w/GL/ DESTINATION ${INCLUDE_INSTALL_DIR}/GL) +install(DIRECTORY thirdparty/gl3w/KHR/ DESTINATION ${INCLUDE_INSTALL_DIR}/KHR) install(FILES thirdparty/imgui/imgui.h thirdparty/imgui/imconfig.h thirdparty/imgui/imgui_internal.h thirdparty/imgui/imstb_textedit.h DESTINATION ${INCLUDE_INSTALL_DIR}) install(FILES thirdparty/implot/implot.h thirdparty/implot/implot_internal.h DESTINATION ${INCLUDE_INSTALL_DIR}) install(FILES thirdparty/portable-file-dialogs/portable-file-dialogs.h DESTINATION ${INCLUDE_INSTALL_DIR}) From 6c9ee22daeca78a31858b05bea05a61ca3eec214 Mon Sep 17 00:00:00 2001 From: Rasmus Diederichsen Date: Sun, 1 Dec 2024 19:24:21 +0100 Subject: [PATCH 5/9] add missing glfw3 dependency --- cmake/iridescence-config.cmake.in | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/iridescence-config.cmake.in b/cmake/iridescence-config.cmake.in index 0aa1ca10..fe5ee6fb 100644 --- a/cmake/iridescence-config.cmake.in +++ b/cmake/iridescence-config.cmake.in @@ -16,6 +16,7 @@ find_dependency(PNG) find_dependency(JPEG) find_dependency(glm) find_dependency(assimp) +find_dependency(glfw3) include("${CMAKE_CURRENT_LIST_DIR}/iridescence-targets.cmake") add_library(Iridescence::Iridescence ALIAS Iridescence::iridescence) From 4bece2db4e69dbf2c7c414d7e6081440195ecb7f Mon Sep 17 00:00:00 2001 From: Rasmus Diederichsen Date: Fri, 6 Dec 2024 12:52:51 +0100 Subject: [PATCH 6/9] Reduce opengl version to make it work on macos sequoia --- src/guik/imgui_application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guik/imgui_application.cpp b/src/guik/imgui_application.cpp index 2992e61d..fc003dac 100644 --- a/src/guik/imgui_application.cpp +++ b/src/guik/imgui_application.cpp @@ -48,7 +48,7 @@ bool Application::init(const Eigen::Vector2i& size, const char* glsl_version, bo } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); if (background) { glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); From 4a4aa5358824db1df5c5438d99c378e4158e24a5 Mon Sep 17 00:00:00 2001 From: Rasmus Diederichsen Date: Mon, 28 Jul 2025 07:39:28 +0200 Subject: [PATCH 7/9] pick_depth(): return closest depth inside window --- src/guik/gl_canvas.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/guik/gl_canvas.cpp b/src/guik/gl_canvas.cpp index 17af155f..1d4870df 100644 --- a/src/guik/gl_canvas.cpp +++ b/src/guik/gl_canvas.cpp @@ -581,17 +581,18 @@ float GLCanvas::pick_depth(const Eigen::Vector2i& p, int window) const { } std::sort(ps.begin(), ps.end(), [=](const Eigen::Vector2i& lhs, const Eigen::Vector2i& rhs) { return lhs.norm() < rhs.norm(); }); + float min_depth = 1; for (int i = 0; i < ps.size(); i++) { Eigen::Vector2i p_ = p + ps[i]; int index = ((size[1] - p[1]) * size[0] + p_[0]); float depth = pixels[index]; - if (depth < 1.0f) { - return depth; + if (depth < 1.0f && depth < min_depth) { + min_depth = depth; } } - return 1.0f; + return min_depth; } /** From c6a6016694986cefeefefd9952b065e437e0b94a Mon Sep 17 00:00:00 2001 From: Rasmus Diederichsen Date: Mon, 28 Jul 2025 07:39:46 +0200 Subject: [PATCH 8/9] scale frame buffer size with window scale --- src/guik/imgui_application.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/guik/imgui_application.cpp b/src/guik/imgui_application.cpp index fc003dac..cd4986f3 100644 --- a/src/guik/imgui_application.cpp +++ b/src/guik/imgui_application.cpp @@ -37,7 +37,12 @@ Application ::~Application() { // dirty implementation std::unordered_map appmap; void fb_size_callback(GLFWwindow* window, int width, int height) { - appmap[window]->framebuffer_size_callback(Eigen::Vector2i(width, height)); + GLFWmonitor* screen = glfwGetWindowMonitor(window); + float xscale, yscale; + glfwGetMonitorContentScale(screen, &xscale, &yscale); + appmap[window]->framebuffer_size_callback(Eigen::Vector2i(width/xscale, height/yscale)); + + } bool Application::init(const Eigen::Vector2i& size, const char* glsl_version, bool background, const std::string& title) { From 134f4e1c574ccd41563f87e5f6159ff068fff66b Mon Sep 17 00:00:00 2001 From: Rasmus Diederichsen Date: Mon, 28 Jul 2025 15:25:51 +0200 Subject: [PATCH 9/9] Use display scaling factor on macos --- src/guik/imgui_application.cpp | 120 +++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 5 deletions(-) diff --git a/src/guik/imgui_application.cpp b/src/guik/imgui_application.cpp index cd4986f3..5f9f801e 100644 --- a/src/guik/imgui_application.cpp +++ b/src/guik/imgui_application.cpp @@ -34,15 +34,125 @@ Application ::~Application() { glfwTerminate(); } +// Retrieve monitor that contains most of a window. +static bool glfw_get_window_monitor(GLFWmonitor** monitor, GLFWwindow* window) { + bool success = false; + + int window_rectangle[4] = {0}; + glfwGetWindowPos(window, &window_rectangle[0], &window_rectangle[1]); + glfwGetWindowSize(window, &window_rectangle[2], &window_rectangle[3]); + + int monitors_size = 0; + GLFWmonitor** monitors = glfwGetMonitors(&monitors_size); + + GLFWmonitor* closest_monitor = NULL; + int max_overlap_area = 0; + + for (int i = 0; i < monitors_size; ++i) + { + int monitor_rectangle[4] = {0}; + glfwGetMonitorWorkarea(monitors[i], &monitor_rectangle[0], &monitor_rectangle[1], &monitor_rectangle[2], &monitor_rectangle[3]); + + const GLFWvidmode* monitor_video_mode = glfwGetVideoMode(monitors[i]); + + if ( + !( + ((window_rectangle[0] + window_rectangle[2]) < monitor_rectangle[0]) || + (window_rectangle[0] > (monitor_rectangle[0] + monitor_rectangle[2])) || + ((window_rectangle[1] + window_rectangle[3]) < monitor_rectangle[1]) || + (window_rectangle[1] > (monitor_rectangle[1] + monitor_rectangle[3])) + ) + ) { + int intersection_rectangle[4] = {0}; + + // x, width + if (window_rectangle[0] < monitor_rectangle[0]) + { + intersection_rectangle[0] = monitor_rectangle[0]; + + if ((window_rectangle[0] + window_rectangle[2]) < (monitor_rectangle[0] + monitor_rectangle[2])) + { + intersection_rectangle[2] = (window_rectangle[0] + window_rectangle[2]) - intersection_rectangle[0]; + } + else + { + intersection_rectangle[2] = monitor_rectangle[2]; + } + } + else + { + intersection_rectangle[0] = window_rectangle[0]; + + if ((monitor_rectangle[0] + monitor_rectangle[2]) < (window_rectangle[0] + window_rectangle[2])) + { + intersection_rectangle[2] = (monitor_rectangle[0] + monitor_rectangle[2]) - intersection_rectangle[0]; + } + else + { + intersection_rectangle[2] = window_rectangle[2]; + } + } + + // y, height + if (window_rectangle[1] < monitor_rectangle[1]) + { + intersection_rectangle[1] = monitor_rectangle[1]; + + if ((window_rectangle[1] + window_rectangle[3]) < (monitor_rectangle[1] + monitor_rectangle[3])) + { + intersection_rectangle[3] = (window_rectangle[1] + window_rectangle[3]) - intersection_rectangle[1]; + } + else + { + intersection_rectangle[3] = monitor_rectangle[3]; + } + } + else + { + intersection_rectangle[1] = window_rectangle[1]; + + if ((monitor_rectangle[1] + monitor_rectangle[3]) < (window_rectangle[1] + window_rectangle[3])) + { + intersection_rectangle[3] = (monitor_rectangle[1] + monitor_rectangle[3]) - intersection_rectangle[1]; + } + else + { + intersection_rectangle[3] = window_rectangle[3]; + } + } + + int overlap_area = intersection_rectangle[2] * intersection_rectangle[3]; + if (overlap_area > max_overlap_area) + { + closest_monitor = monitors[i]; + max_overlap_area = overlap_area; + } + } + } + + if (closest_monitor) + { + *monitor = closest_monitor; + success = true; + } + + // true: monitor contains the monitor the window is most on + // false: monitor is unmodified + return success; +} + // dirty implementation std::unordered_map appmap; void fb_size_callback(GLFWwindow* window, int width, int height) { - GLFWmonitor* screen = glfwGetWindowMonitor(window); - float xscale, yscale; - glfwGetMonitorContentScale(screen, &xscale, &yscale); - appmap[window]->framebuffer_size_callback(Eigen::Vector2i(width/xscale, height/yscale)); - + float xscale = 1, yscale = 1; + // retrieve display scaling factor (needed on macos, otherwise resizing breaks mouse + // interaction) + GLFWmonitor* screen; + if (glfw_get_window_monitor(&screen, window)) { + glfwGetMonitorContentScale(screen, &xscale, &yscale); + } + appmap[window]->framebuffer_size_callback(Eigen::Vector2i(width/xscale, height/yscale)); } bool Application::init(const Eigen::Vector2i& size, const char* glsl_version, bool background, const std::string& title) {