-
Notifications
You must be signed in to change notification settings - Fork 440
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
Correct out-of-the-box HiDPI support in SDL, GLFW and Android apps #243
Comments
I just came across Magnum for the first time and it shocks me that all the WebGL showcase examples in the website look blurred and non-retina. Good to know this is being addressed, hope the web demos in the showcase could be updated soon, this way new people interested on using Magnum wouldn't get confused about retina support. |
@noisiak oh, thanks for the reminder, almost forgot it's a problem on WebGL as well. Didn't investigate yet how is it with Emscripten (and WebGL in general) and HiDPI. Any hints where I should look? |
(The still unreleased) GLFW 3.3 has a window content scale callback corresponding to |
@elmindreda yay, awesome, thanks for letting me know :) GLFW is great. |
Showcase on http://magnum.graphics/showcase/ is updated with proper HiDPI support since mosra/magnum-website@f0ffb93. |
Initial support in GLFW apps (matching the SDL support 1:1) is done in dba35ba. |
(The still unreleased) GLFW 3.3 now has the |
@elmindreda amazing, thank you again 👍 Looking forward to all the code I can delete once 3.3 is out :) |
Moving the rest of this issue (and especially Windows DPI autodetection) to the next milestone. Otherwise I would never release anything ;) |
Windows support (w/o |
I attempted to implement DPI change events as well, since that's the last major item left, but it opened quite a lot of new questions, so moving that to a WIP PR in #423. |
Got myself a Spectre x360 with 4K screen and the current HiDPI "support" in Magnum is making me sad so I did some research. Saving it for the moment, postponing to after #233 is done as this is apparently a bit more work than just flipping a switch in SDL.
What needs to be done:
SDL_GetDisplayDPI()
returns 282,xrdb -query | grep Xft.dpi
returns (correct) 230). Further info about how to implement and how to get this in GLFW. Make the latter the default on Linux (and possible to fall back to physical? or does xrdb return the physical value if not overriden?) On the other hand, does the builtin DPI query in SDL report the correct virtual (not physical) DPI on Win / macOS? GLFW will have this in 3.3.glfwGetContentScale()
on GLFW 3.3+ instead of the direct queries? Unfortunately the code has a fallback to physical DPI if retrieval of given value fails (https://github.com/glfw/glfw/blob/1bf892f603b2479666b0035eb1bc214b05364ad7/src/x11_init.c#L794-L828), which was subsequently removed as KDE seems to unsetXft.dpi
if content scaling is 100% (glfw/glfw@399c082) so it's not really any better than mine as the fallback is implicit without giving the user any option to pick one or the other.SDL_GetDisplayDPI()
does both as of 2.0.22 (In x11, GetDisplayDPI can give incorrect or unusable DPI information.… libsdl-org/SDL#4220), but in my case (on 2.0.28) it doesn't seem to work and returns some imprecise value instead. So the same implicit fallback out of user control as with GLFW but without a workaround KDE unsettingXft.dpi
, so again, the direct queries I have seem to be superior.KDE_SESSION_UID
env var) and fallback for theXft.dpi
codeXft.dpi
code (branching based onXDG_SESSION_TYPE
beingx11
orwayland
? getting some Wayland "context" handle from GLFW and SDL?)Application::Configuration
(e.g. override to 1.73, completely disable when things go really bad (misconfigured X11, e.g.), switching between physical and virtual dpi?)--magnum-dpi-scaling
command-line option and environment -- done for SDL2 on Linux and Emscripten in ae31c3c, for GLFW in dba35baSDL_GL_GetDrawableSize()
(andSDL_Vulkan_GetDrawableSize()
explicitly next to the new reported window size from the event. Do it via a new ViewportEvent type, deprecate the old event function. -- done for all apps in c0125fa, 25d0bb8, ed0a719glfwGetMonitorContentScale()
to get virtual DPI scaling on Windows -- 444b925With this, an 800x600 window should ideally have the same physical size regardless of monitor DPI. Question is about relation of framebuffer size and virtual screen size (coordinate system for events):
Should it be always the same as the requested size? That might not be possible under X11, because there it seems to be always 1:1 relation between pixels and points. SDL has SDL_RenderSetLogicalSize(), but that's not for GL/Vulkan it seems. GLFW 3.3 will have GLFW_HIDPI_RESIZE.Or, does it matter at all if its consistent or if its consistent across platforms? In the end there's some projection matrix that does the final scaling of scene coordinates to window coordinates, the only problem is event handling, but for that we can tell users to always querywindowSize()
and scale their event coordinates (currently reported as integers in both SDL and GLFW App implementation) according to that value. Moreover, the UI library already is designed with this in mind.The following needs to be verified:
Further work:
dpiScaling()
query is relative to window size, which is 1 on macOS, so not helpful. Or makedpiScaling()
relative to framebuffer size? Would that solve it? Or break something else?Responding to events when the app is moved across monitors with different DPI.Extremely complex topic on its own, moved to DPI change events in Sdl2App and GlfwApp #423.Events in Emscripten apps in the browser on Android probably suffer from some DPI scaling problem, investigate (can't click on anything in the UI gallery)-- not a problem in the new EmscriptenApplication anymore, was something in the emscripten SDL emulation layer (Emscripten application #300)AndroidApplication
as well -- getting separate window, framebuffer (there isANativeWindow_Buffer
, could that be used?) and DPI scaling values (NDK can give me only an enum for DPI scaling, do I need to use JNI? https://stackoverflow.com/a/18858569 What about the framebuffer size?) -- "just works" as long as the app is targeting new enough SDK, FB size is then same as window sizeINTERFACE_SOURCES
ofMagnum::*Application
CMake targets? Could make it nicely "just work" for all examples, without need for manual boilerplate. What about macOS / iOS? Also needs a way to disable such behavior.Related info:
The text was updated successfully, but these errors were encountered: