-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
High DPI scaling on Mac OS and glfw #5081
Comments
My solution is change draw_data->FramebufferScale at function SetupViewportDrawData |
Some related discussion: https://bitbucket.org/wolfpld/tracy/issues/42/cannot-scroll-down-capture-on-macos |
#5301 also a relevant issue with a workaround. |
I experienced this issue with GLFW and Wayland. I worked-around it with this patch: https://gist.github.com/TheBrokenRail/9ed21b810a4f33a5b1bb062024573128 It:
This works on Wayland, where just like macOS, "screen coordinates can be scaled relative to pixel coordinates" (to quote the GLFW documentation). It also works on X11, where just like Windows, "screen coordinates and pixels always map 1:1" (also quoting GLFW). |
That sounds about right, and is more or less what I did in a (non-imgui) work project to get hidpi on macos. |
I am hoping to tackle this on Q1 2025, but yes that's basically it above. The more tricky aspect is to understand how coordinates and transform would work in multi-viewport multi-monitor mode. If you have access to a Mac setup where one monitor is hi-dpi and the other isn't, it would be the ideal test-bed and I'd be happy if you can report on this. Not having investigated this is the primary blocker for me. EDIT The transform would also generally apply when interacting with the windowing system. |
Version/Branch of Dear ImGui:
Version: 1.87, 1.88 WIP
Branch: docking & viewport
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: clang
Operating System: Mac OS Monterey, Mac Mini M1
My Issue/Question:
Hello,
I know the questions about high DPI scaling have been asked a lot around here, however I do not think that I found a solution in the github issues.
My goal is to have an application that correctly DPI scaling. So I am following the instructions shown here. In the main loop, I checking if the scaling of the main window changed and I rebuild the fonts accordingly:
So, this solution works fine on windows, and my fonts are not blurry and are correctly scaled.
However, on Mac OS the window of glfw is by default already scaled, so if I scale the fonts, then I get this:

One quick solution would be to not scale the font at all, but then I obtain text that is at the correct scale, but blurry:

My first initial guess was to look at the glfw window hints, like
GLFW_SCALE_TO_MONITOR
andGLFW_COCOA_RETINA_FRAMEBUFFER
. The first hint does not seem to change anything, and the second hint does not help either, because it isGLFW_TRUE
by default.With
GLFW_COCOA_RETINA_FRAMEBUFFER
set toGLFW_TRUE
, the framebuffer size of the main windowreturns the actual number of pixels the window takes, not virtual pixels. This means on my 4K screen, if I fullscreen the main window,
display_w
will have 3860 pixels.Searching further, I found that #3757 exposes a similar problem to mine, but with the SDL. The author of the issue provided a temporary fix. I tried to implement the fix in
imgui_impl_glfw.cpp
like this:This does, along with the scaled font, produces the result I want:

However, the mouse interaction does not work, because ImGui thinks that the mouse coordinates are in virtual pixels (I use glfw terms), but the UI is rendered in true pixels. I looked at
but I failed to provide a valid fix, because glfw provides virtual pixels positions (for both the callback and
glfwGetWindowPos
). This means if I have a 3680x2160px screen and a scaling of 2, with a mouse position of 400x200 the callback will return 200x100.Multiplying the mouse position by the scale like in #3757 does not work, and this is because glfw always provides virtual pixel coordinates.
Do you know how I could resolve this ? I found a way to have the mouse coordinates match the window like this (with the viewport flags):
but this is obviously wrong because even if I can interact correctly with the widgets inside the main window, it means that I can also interact with widget when the mouse is outside the window...
Thank you in advance
The text was updated successfully, but these errors were encountered: