Skip to content
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

Unification of HDPI scaling across platforms #677

Closed
badlogic opened this issue Dec 29, 2015 · 8 comments
Closed

Unification of HDPI scaling across platforms #677

badlogic opened this issue Dec 29, 2015 · 8 comments
Assignees
Labels
enhancement Feature suggestions and PRs High DPI High resolution display specific
Milestone

Comments

@badlogic
Copy link

On Mac OS X, GLFW reports screen sizes and framebuffer sizes properly if upscaling is enabled in the OS. E.g. on a "retina" display at 2x upscaling, creating a window at 900x600 screen size will result in a 1800x1200 frame buffer size.

For the same scenario on Windows, with HDPI scaling set to 200%, the window size is actually interpreted as the framebuffer size, not the screen size. This results in a window of framebuffer size 900x600 pixels instead of 1800x1200 pixels. The window's screen size is then actually smaller as what was specified during window creation (450x300 at 200% upscaling). However, GLFW reports the framebuffer size as the screen size (900x600), which makes detection and handling of HDPI upscaling impossible on Windows.

I have not tested this on Linux. My assumption would be that it probably works like on Windows (screen size == framebuffer size irrespective of upscaling settings).

It'd be great if this worked the same on all operating systems, preferably the way it works on Mac OS X, with the screen size and framebuffer size being reported according to the upscaling setting of the OS.

If fixing this transparently is not possible, it'd be great if GLFW could expose the upscaling factor so users can perform platform specific work-arounds.

@badlogic badlogic changed the title Unification HDPI scaling across platforms Unification of HDPI scaling across platforms Dec 29, 2015
@j6lim
Copy link

j6lim commented Dec 30, 2015

+1

@elmindreda elmindreda added the enhancement Feature suggestions and PRs label Feb 26, 2016
@elmindreda elmindreda self-assigned this Feb 26, 2016
@elmindreda elmindreda added the High DPI High resolution display specific label Mar 13, 2016
elmindreda referenced this issue Dec 29, 2016
Look, a can of worms!  I wonder what's inside.

This adds the first platform specific window hint, transforming
a compile-time option to a run-time per-window one.
@claudiofantacci
Copy link

Hello, I was looking for updates on this issue and I just read this commit.

Am I correct saying that GLFW_HIDPI_RESIZEwindow hint will be released in the next GLFW release (3.3)?

@felselva
Copy link
Contributor

I have not tested this on Linux. My assumption would be that it probably works like on Windows (screen size == framebuffer size irrespective of upscaling settings).

I don't believe this feature is needed on Linux.

On Linux, HDPI is defined by the desktop enviroment, and there are many desktop enviroment. Each DE will report the HDPI scale in a different way (may be a configuration file, using a library or a configuration system like dconf). Best way is to check how the DEs that you want to support HDPI report these and implement a solution for them.

@claudiofantacci
Copy link

By my understanding of this documentation

GLFW_HIDPI_RESIZE specifies whether the windowed mode window will resize
either its framebuffer or both itself and the framebuffer when it is moved to
a monitor with a significantly different DPI.

On Windows 8.1 and later, this will cause both the window and its
framebuffer to resize when it is moved to a monitor with a different DPI.  The
new size makes the window appear approximately as large (measured in mm on the
monitor) as on the previous monitor.  If disabled the window will not be resized
when moved between monitors.

On OS X 10.7 and later, if enabled this hint will cause the
framebuffer of the window to resize to an integer multiple of the window size,
letting OpenGL render at the full resolution of Retina monitors while the rest
of the UI appears not to resize.  If disabled rendering will not use Retina
resolution in either full screen or windowed modes.

and by the X11 behaviour described in this comment

On X11 you only get a DPI value and have to do the rest yourself.
Pixels and screen coordinates always map 1:1 (modulo compositors) and the
window system has no concept of a high-DPI mode.

the new feature should only affect Windows and macOS OSs.

@elmindreda elmindreda added this to the 3.3 milestone Mar 27, 2017
elmindreda added a commit that referenced this issue Oct 26, 2017
This adds glfwGetWindowContentScale and glfwGetMonitorContentScale for
querying the recommended drawing scale factor for DPI-aware rendering.

Parts of this patch are based on code by @ferreiradaselva.

Fixes #235.
Fixes #439.
Fixes #677.
Fixes #845.
Fixes #898.
elmindreda added a commit that referenced this issue Oct 26, 2017
This adds glfwGetWindowContentScale and glfwGetMonitorContentScale for
querying the recommended drawing scale factor for DPI-aware rendering.

Parts of this patch are based on code by @ferreiradaselva.

Fixes #235.
Fixes #439.
Fixes #677.
Fixes #845.
Fixes #898.
elmindreda added a commit that referenced this issue Jan 9, 2018
@edwinRNDR
Copy link

I am (still) seeing the same issues as originally reported by @badlogic on master (34d20b0). On Windows 10 the window size is equal to framebuffer size on systems that report a content scaling of 2.0. Is this the intended behaviour? If so what tools are there to make sure I am creating the window at the right size?

@elmindreda
Copy link
Member

elmindreda commented Jul 12, 2019

That is the intended behavior. The window size and framebuffer size will always match on Windows and X11. On those platforms, the window (and framebuffer) is resized according to the monitor's scale. If you have GLFW_SCALE_TO_MONITOR enabled and tell GLFW to create a 640x480 window on a monitor with scaling factor 2.0, the initial size of both the window and framebuffer will be 1280x960.

Edit: If you then move it to a monitor with scaling factor 1.5, it will resize (window and framebuffer) to 960x720.

@mokafolio
Copy link

@elmindreda ugh, i deleted the comment because I realized I was accidentally still linking against the glfw that I installed with apt and your response was not showing at the time.

So what is the proper way to deal with the differences across platforms then? i.e. On windows and ubuntu I get the same value for window size and framebuffer but what I really want to get from window size is the original size I put in because i.e. I use that to setup certain projections. To handle this case properly, will I need to check platform and the scalefactor and do the right thing accordingly?

Wouldn't it be better if glfw decides on one way of how to go about this and consistently does it across platforms? I am propably missing something, just thinking out loud.

Thanks!

@mokafolio
Copy link

mokafolio commented Jul 12, 2019

Just to illustrate why I agree with @badlogic that the way osx does it is better (i.e. separate between window size and framebuffer size). Let's say you have some code that works in a sequence like this:

  1. create window at 800x600
  2. create an ortho projection based on glfwGetWindowSize
  3. draw stuff hardcoded based on that window size (i.e. at the center, 400x300)

While in a lot of high end code, you'll hopefully not encounter this, it is very common for basic examples (where glfw is used very often).

On osx, the above still works perfectly fine. On linux (and windows) this wont work anymore without doing a lot of extra lifting to determine if we are on a hidpi display or not etc.

Either way, I think it would be lovely if glfw would pick one way (i.e. either the windows/linux or osx) and stick with it.

nbilyk added a commit to polyforest/acornui that referenced this issue Aug 29, 2019
GlfwMouseInput - add a conversion between window coordinates and
canvas point coordinates.
glfw/glfw#677
m4ce-w1ndu pushed a commit to m4ce-w1ndu/glfw that referenced this issue Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature suggestions and PRs High DPI High resolution display specific
Projects
None yet
Development

No branches or pull requests

7 participants