diff --git a/examples/demo-app/demo_app.cpp b/examples/demo-app/demo_app.cpp index 96cb093c..139fa41b 100644 --- a/examples/demo-app/demo_app.cpp +++ b/examples/demo-app/demo_app.cpp @@ -879,7 +879,7 @@ int main(int argc, char** argv) { // polyscope::view::windowWidth = 600; // polyscope::view::windowHeight = 800; // polyscope::options::maxFPS = -1; - polyscope::options::verbosity = 100; + polyscope::options::verbosity = 101; polyscope::options::enableRenderErrorChecks = true; polyscope::options::allowHeadlessBackends = true; diff --git a/src/imgui_config.cpp b/src/imgui_config.cpp index 86acbca3..be0cd1d9 100644 --- a/src/imgui_config.cpp +++ b/src/imgui_config.cpp @@ -16,13 +16,16 @@ const unsigned int* getLatoRegularCompressedData(); void configureImGuiStyle() { - // Style ImGuiStyle* style = &ImGui::GetStyle(); - style->WindowRounding = 1 * options::uiScale; - style->FrameRounding = 1 * options::uiScale; - style->FramePadding.y = 4 * options::uiScale; - style->ScrollbarRounding = 1 * options::uiScale; - style->ScrollbarSize = 20 * options::uiScale; + *style = ImGuiStyle(); // apply the default style as a starting point + + // Style + style->WindowRounding = 1; + style->FrameRounding = 1; + style->FramePadding.y = 4; + style->ScrollbarRounding = 1; + style->ScrollbarSize = 20; + style->ScaleAllSizes(options::uiScale); // Colors @@ -77,21 +80,34 @@ std::tuple prepareImGuiFonts() { ImGuiIO& io = ImGui::GetIO(); + ImVec2 windowSize{static_cast(view::windowWidth), static_cast(view::windowHeight)}; + ImVec2 bufferSize{static_cast(view::bufferWidth), static_cast(view::bufferHeight)}; + ImVec2 imguiCoordScale = {bufferSize.x / windowSize.x, bufferSize.y / windowSize.y}; + // outputs - ImFontAtlas* fontAtlas; + ImFontAtlas* fontAtlas = nullptr; // right now this is unused by the caller, but I don't want to change + // this callback signature until I'm more confident about how this + // should work. (And it might be changing in an upcoming imgui version) ImFont* regularFont; ImFont* monoFont; + float fontSize = 16.0 * options::uiScale; + fontSize = std::max(1.0f, std::roundf(fontSize)); + { // add regular font ImFontConfig config; + config.RasterizerDensity = std::max(imguiCoordScale.x, imguiCoordScale.y); regularFont = io.Fonts->AddFontFromMemoryCompressedTTF(render::getLatoRegularCompressedData(), - render::getLatoRegularCompressedSize(), options::uiScale*18.0f, &config); + render::getLatoRegularCompressedSize(), + options::uiScale * 18.0f, &config); } { // add mono font ImFontConfig config; + config.RasterizerDensity = std::max(imguiCoordScale.x, imguiCoordScale.y); monoFont = io.Fonts->AddFontFromMemoryCompressedTTF(render::getCousineRegularCompressedData(), - render::getCousineRegularCompressedSize(), options::uiScale*16.0f, &config); + render::getCousineRegularCompressedSize(), + options::uiScale * 16.0f, &config); } // io.Fonts->AddFontFromFileTTF("test-font-name.ttf", 16); diff --git a/src/render/opengl/gl_engine.cpp b/src/render/opengl/gl_engine.cpp index eff22285..81f77676 100644 --- a/src/render/opengl/gl_engine.cpp +++ b/src/render/opengl/gl_engine.cpp @@ -1078,7 +1078,7 @@ void GLCompiledProgram::compileGLProgram(const std::vector 2) { printShaderInfoLog(h); } - if (options::verbosity > 100) { + if (options::verbosity > 200) { std::cout << "Program text:" << std::endl; std::cout << s.src.c_str() << std::endl; } diff --git a/src/render/opengl/gl_engine_glfw.cpp b/src/render/opengl/gl_engine_glfw.cpp index 6b3f2ca9..9333931c 100644 --- a/src/render/opengl/gl_engine_glfw.cpp +++ b/src/render/opengl/gl_engine_glfw.cpp @@ -51,7 +51,7 @@ void GLEngineGLFW::initialize() { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // This tells GLFW to scale window size/positioning/content based on the system-reported DPI scaling factor - // However, it can lead to some confusing behaviors, for instance, on linux with scaling=200%, if the user + // However, it can lead to some confusing behaviors, for instance, on linux with scaling=200%, if the user // sets view::windowWidth = 1280, they might get back a window with windowWidth == bufferWidth == 2560, // which is quite confusing. // For this reason we _do not_ set this hint. If desired, the user can specify a windowWidth = 1280*uiScale, @@ -80,14 +80,6 @@ void GLEngineGLFW::initialize() { setWindowResizable(view::windowResizable); - // Set the UI scale to account for system-requested DPI scaling - // Currently we do *not* watch for changes of this value e.g. if a window moves between - // monitors with different DPI behaviors. We could, but it would require some logic to - // avoid overwriting values that a user might have set. - if(options::uiScale < 0) { // only set from system if the value is -1, meaning not set yet - setUIScaleFromSystemDPI(); - } - // === Initialize openGL // Load openGL functions (using GLAD) #ifndef __APPLE__ @@ -117,18 +109,39 @@ void GLEngineGLFW::initialize() { // glClearDepth(1.); } + // Set the UI scale to account for system-requested DPI scaling + // Currently we do *not* watch for changes of this value e.g. if a window moves between + // monitors with different DPI behaviors. We could, but it would require some logic to + // avoid overwriting values that a user might have set. + if (options::uiScale < 0) { // only set from system if the value is -1, meaning not set yet + setUIScaleFromSystemDPI(); + } + populateDefaultShadersAndRules(); } void GLEngineGLFW::setUIScaleFromSystemDPI() { - - float xScale, dont_use_yScale; - glfwGetWindowContentScale(mainWindow, &xScale, &dont_use_yScale); - // clamp to values within [1x,4x] scaling - xScale = std::fmin(std::fmax(xScale, 1.0f), 4.0f); + // logic adapted from a helpful imgui issue here: https://github.com/ocornut/imgui/issues/6967#issuecomment-2833882081 + + ImVec2 windowSize{static_cast(view::windowWidth), static_cast(view::windowHeight)}; + ImVec2 bufferSize{static_cast(view::bufferWidth), static_cast(view::bufferHeight)}; + ImVec2 imguiCoordScale = {bufferSize.x / windowSize.x, bufferSize.y / windowSize.y}; - options::uiScale = xScale; + ImVec2 contentScale; + glfwGetWindowContentScale(mainWindow, &contentScale.x, &contentScale.y); + + float sx = contentScale.x / imguiCoordScale.x; + float sy = contentScale.y / imguiCoordScale.y; + options::uiScale = std::max(sx, sy); + // clamp to values within [0.5x,4x] scaling + options::uiScale = std::fmin(std::fmax(options::uiScale, 0.5f), 4.0f); + + info(100, "window size: " + std::to_string(view::windowWidth) + "," + std::to_string(view::windowHeight)); + info(100, "buffer size: " + std::to_string(view::bufferWidth) + "," + std::to_string(view::bufferHeight)); + info(100, "imguiCoordScale: " + std::to_string(imguiCoordScale.x) + "," + std::to_string(imguiCoordScale.y)); + info(100, "contentScale: " + std::to_string(contentScale.x) + "," + std::to_string(contentScale.y)); + info(100, "computed uiScale: " + std::to_string(options::uiScale)); } void GLEngineGLFW::initializeImGui() { @@ -146,7 +159,7 @@ void GLEngineGLFW::initializeImGui() { void GLEngineGLFW::configureImGui() { - if(options::uiScale < 0){ + if (options::uiScale < 0) { exception("uiScale is < 0. Perhaps it wasn't initialized?"); } @@ -161,7 +174,7 @@ void GLEngineGLFW::configureImGui() { ImFontAtlas* _unused; std::tie(_unused, regularFont, monoFont) = options::prepareImGuiFontsCallback(); - + ImGui_ImplOpenGL3_CreateFontsTexture(); } @@ -172,7 +185,6 @@ void GLEngineGLFW::configureImGui() { } - void GLEngineGLFW::shutdown() { checkError(); shutdownImGui();