Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upDPI problem umbrella issue #587
Comments
icefoxen
added
bug
Type-CODE
*HARD*
dependency bug
labels
Feb 18, 2019
icefoxen
added this to the 0.5 milestone
Feb 18, 2019
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
seivan
commented
Feb 19, 2019
|
@icefoxen The only thing I'm not sure of is if |
icefoxen
pinned this issue
Feb 19, 2019
This comment has been minimized.
This comment has been minimized.
|
Found some pretty good references on OSX stuff: https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/APIs/APIs.html#//apple_ref/doc/uid/TP40012302-CH5-SW2 . Rummage around other things in that section for more info. I like how they explain their reasoning on why you should never need to use the various tools they give you. It all makes perfect sense if a) pixels are actually invisible, b) it always works the same across every device (and OS), c) Retina displays never get bigger or smaller, and d) you never care about degenerate cases like aliasing or moire effects because e) OSX's Magic Drawing Hints fix everything for you behind the scenes. Unfortunately, the real world is seldom this tidy. I'm not bitter, honest. |
This comment has been minimized.
This comment has been minimized.
hughlang
commented
Mar 6, 2019
|
Please see my latest comment on #553. I spent enough time with this to feel like I can help out. And I can test on mac, linux, and windows. Thanks. |
This comment has been minimized.
This comment has been minimized.
|
@hughlang I'd love some help, thanks! Sorry for the delay in getting back to you. This is definitely something I'd like help with, it's just tough 'cause I'm so frustrated with it I can't stand to try to deal with it more than once every three weeks apparently. :-P |
This comment has been minimized.
This comment has been minimized.
hughlang
commented
Mar 10, 2019
|
Thanks! I researched other projects that had a similar hidpi problem. I found this to be a little relevant: https://github.com/PistonDevelopers/glutin_window/pull/149/files It seems like they ditched hidpi checking in favor of the to_physical() method call. Maybe the nonsense of hidpi is now fixed upstream. |
This comment has been minimized.
This comment has been minimized.
|
It's implied to be fixed in the response to rust-windowing/winit#796 but I just haven't had the time to dig through and see how complete and comprehensive the fix actually is. If winit provides a nice way to actually give us real resolution numbers, we should use it everywhere necessary. |
icefoxen
referenced this issue
Apr 2, 2019
Closed
Wrong window dimensions, unwanted scaling (Linux, X11) #615
This comment has been minimized.
This comment has been minimized.
What happens is actually kinda interesting, so I'm going to write it down. On any platform, without a hidpi display (hidpi_factor = 1.0) it has no difference, as one would expect. On Linux, with no active hidpi code, it works as intended and gives you things the size you ask them for without the hidpi scaling. On OSX with a retina display, it gives you a window that is still scaled for hidpi but the existing graphics bug with scaling gets worse (#553), it draws everything at 1/4 size instead of 1/2. On Windows, it mostly works but in the astroblasto example at least the text at the top of the screen is half cut off by the window title bar. So something's screwy there. (Actually that happens even with vanilla ggez, it seems. Sigh.) |
icefoxen
referenced this issue
Apr 4, 2019
Closed
[question] spritebatch, stripes between images #616
icefoxen
added a commit
that referenced
this issue
Apr 4, 2019
This comment has been minimized.
This comment has been minimized.
|
Well I started messing around in 5aedef4 and scarily it doesn't seem like complete nonsense, yet. In fact on Linux it seems to work and work really well, though I'm sure there are some whack edge cases that still need handling, as described in that commit message, plus probably more. So... It might be the obvious way forward. |
This comment has been minimized.
This comment has been minimized.
|
The "hack around to force no hidpi scaling ever" branch seems to work better than I expected, though it's not flawless. Things that need fixed:
|
This comment has been minimized.
This comment has been minimized.
hughlang
commented
Apr 16, 2019
|
Thanks @icefoxen |
This comment has been minimized.
This comment has been minimized.
hughlang
commented
Apr 17, 2019
•
|
I researched the MacOS scaling bug a bunch this morning, since I need a solution for this. Here are my findings. TLDR, you already are on the right path with handling Winit's HiDpiFactorChanged event in process_event. First, the subverted_size is incorrect for anything outside of DPI factor 1.0. It forces a logical size that is smaller and not changeable without resetting later. I think that part should be removed or locked at 1.0. 1.0 display:
2.0 display
At the end of the graphics setup, you currently make some calls to set the projection rect/matrix. I assume this is also what you do after you receive the HiDpiFactorChanged event using the new physical size which is double the logical size for macos. |
This comment has been minimized.
This comment has been minimized.
|
Oh, awesome, thank you so much for looking into this. Can you link your example code somewhere? I'll work on this tonight if I can. Basically on MacOS it looks like the conversion is happening twice for whatever reason, we're left with a window that is the right physical size but thinks it's smaller than it actually is. I don't get this behavior on Windows or Linux, is the weird thing. |
This comment has been minimized.
This comment has been minimized.
hughlang
commented
Apr 17, 2019
•
|
I think that was the old behavior when the conversion is happening twice. It depends on how you test it. I've seen some freaky things in how hard-coded floats used in testing have different behaviors than ones assigned to a var first. For example, I was hacking around in src/graphics/context.rs and was messing with these lines:
This behaves the way shown in the debug output above. However, you get a different result if you hard code numbers inside the formula. It goes through one or more size change alerts. I can try to provide some test code, but mine is too dense to be useful. In the end, I think you just need to update the projection matrix. It will start treating the original 1024x768 as 2048x1536 internally when projecting pixels at it. |
This comment has been minimized.
This comment has been minimized.
Now that just doesn't make sense. Unless it somehow thinks that the size it's being told to become is not quite the same as the size the window is created with and it has to resize. |
This comment has been minimized.
This comment has been minimized.
hughlang
commented
Apr 17, 2019
|
I know, but I've also got screenshots and log output that shows that. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Can't reproduce using This sort of nonsense happens even when I force hidpi_factor to be 1.0, so I think I'm just going slowly insane. This has happened before, with me and others, but it's maddening as heck that it's only on mac for some reason: rust-windowing/glutin#287 This may be the culprit: https://docs.rs/glutin/0.20.0/x86_64-apple-darwin/glutin/struct.WindowedContext.html#method.resize Adding the below to the bottom of
The interactions with fullscreen mode is also frustrating. |
This comment has been minimized.
This comment has been minimized.
hughlang
commented
Apr 18, 2019
•
|
Thanks for the research. I will give that a try in the morning. I think the glutin links you post are vaguely similar to the DPI docs on Winit. https://docs.rs/winit/0.18.0/winit/dpi/index.html – Definitely interesting. I'm eager to try changing the projection matrix as an experiment. I feel certain that the subverted size is going to give exactly what it says it will, and I want to try starting with 1.0 sizing and updating after DPI change event. Starting with these lines in src/graphics/context.rs, what do you suggest as code to try out for handling DPI change?
I see a related method Also, I didn't try 800x600 which was a source of problems for ggez/mac in the past, so I will test that as well. |
This comment has been minimized.
This comment has been minimized.
|
Glutin is basically a thin wrapper around Winit these days anyway, hence why the docs look similar. I messed a lot with the projection matrix, to little avail because, I believe, the OpenGL context wasn't getting resized correctly anyway. It looks like it's only covering 1/4 of the screen. Some sort of platform dependent stuff happening there is basically the only way I can explain this problem occuring on mac and not other platforms. The projection matrix itself will be fine if it's given the correct info. I tried throwing |
This comment has been minimized.
This comment has been minimized.
|
HiDPI pees in my cheerios yet again. See https://github.com/ggez/ggez/blob/master/examples/eventloop.rs#L30 . See https://github.com/ggez/ggez/blob/devel/src/event.rs#L169-L170 . Consider what one has to do to make things not break when you try to combine these two. |
This comment has been minimized.
This comment has been minimized.
|
...what has to be done is use the event returned by |



icefoxen commentedFeb 18, 2019
•
edited
Overview of issues:
Demonstration:
Mac-specific problems:
Issues reported due to DPI being incorrect (some SDL, some winit):
Maybe related? The Mac OS Weird Screen Size Problem: