Adjusting window/sprites according to Windows UI scale settings/DPI


I’m taking baby steps into Amethyst at the moment and thought I’d make a very simple “game”; a loading screen displaying a logo. :slight_smile:

So I read through the Book and managed to create a window and transition into a LoadingState, which (on_start) reads a texture to a sprite and displays it using a 2D Camera. So far so good.

Now I have a high resolution/high DPI laptop screen which is quite small so Windows suggests scaling all UI and apps to 250%, which works well in general, but the Amethyst game window gets scaled as well. So the window and all my sprites in it are scaled up 2,5 times so the logo gets unsharp and blurry.

I found a section on DPI in the Amethyst documentation and it mentions you can get the DPI from the active monitor/window, but I can’t seem to find any actual examples on how to do this.

What I’d like to do is to get the DPI from the active monitor in my, before creating any window, so I can take the DPI into account already for the window size and then in all (upcoming) states where I draw something I’d also listen to the DPI change event and adjust accordingly.

I’m using GameDataBuilder with RenderingBundle and plugin RenderToWindow::from_config(display_config) and have not found any way of getting the DPI out from that flow. Maybe I have to create the window in a different way to get the DPI?

Would be glad if someone could point me in the right direction. Thanks!

(OvermindDL1) #2

Amethyst uses winit for windows handling, I ‘think’ in winit there was an option to specify it as hidpi capable, which keeps you at normal 1-to-1 size so you can get the DPI scale to perform your own scaling in amethyst. I’m unsure if amethyst wraps this (I still have an old fashioned 1920x1200 26" monitor, no hidpi) in an easier way, but it should be doable.

1 Like

Yeah, winit has support to get the DPI factor out - I even see it when I run my game:

[INFO][winit::platform::platform::window] Guessed window DPI factor: 2.5

The problem is I need a Window or MonitorId and I don’t know how to get that from the RenderToWindow plugin I’m currently using.

Edit: I guess I need to get it from the Monitor, not the Window, since I want the information before the window has been created… ideally…

1 Like

I also was struggling with this