Hacker News new | past | comments | ask | show | jobs | submit login

> This isn’t often relevant for games, but, if you need to check how much things would have been scaled if you weren’t DPI aware, you can call GetDpiForWindow and divide the result by 96.

If you aren't scaling up text and UI elements based on the DPI then it doesn't really sound like your application is truly DPI aware to me. I don't see why that applies any differently to games versus any other kind of application.




I think it's reasonably common for games to scale their text and UI elements by the overall screen or window size, in which case opting out of clever OS DPI tricks is the right choice. Using actual DPI doesn't make much sense in general - the player could be sitting right in front of their laptop screen or feet away from a big TV, which obviously require very diffent font sizes in real world units.


Yup, you hit the nail on the head (author of the article here). I guess I could've clarified that, I didn't expect people to assume I was advocating against scaling your UIs to fit the user's screen! Many games scale to fit the window by default, and even offer additional controls on top of that.


It's not as simple as just scaling the UI to the size of the screen though, because the UI elements should be bigger at the same screen size if the scaling is higher. That's why, like you mention in the article, you'll be able to tell when the setting has been changed simply by looking at the scale of the UI: because it will be wrongly too small once the setting is activated.


Yup! I'm aware of what DPI scale is for, I use it when I write game tools. I don't use it in game, though--that's an intentional tradeoff I'm making. It seems like a pretty common tradeoff for games though!

If you want to see why, try mocking up a typical shooter HUD. Now try scaling up/down all the elements by 50% and see what happens. Feel free to play with the anchoring, etc. Chances are you're not gonna like what you see! Things get even more complicated when you consider that players with controllers often change their view distance when gaming and don't wanna reconfigure their display all the time.

The typical solution is to fix the UI scale to the window size, and keep the text large enough that it's readable at a large range of DPIs and viewing distances. If you can't get 100% there that way you'll typically add an in-game UI scale option. (The key difference between that and the built in UI scaling in Windows being that it's specific to the game, so you'll set it to something milder than you'd set the Windows option, and it will only affect the game so you don't have to keep changing it back and forth.)

[EDIT] I think I came up with a way to explain this that saves you the trouble of drawing it out yourself. The fundamental issue, view distance changes aside, is that games are balancing a third variable most apps don't have to: how much of the background--the actual game--is the UI occluding?


If you’re scaling based on percentage of overall window dimension, the elements will be the same physical size on two monitors of the same physical size even if one is 1080p and one is 2160p or what have you. It won’t cause you to draw elements with a fixed physical pixel size and draw tiny letters like some accidentally DPI aware Windows applications do.

It is non-ideal for something like a traditional UI element where users may want to alter scaling settings to have more screen space if their monitor is close enough to their eyes, but for a game HUD that usually isn’t the desired effect anyway.


But in those cases you'd expect the user to manually adjust their scaling settings, which wouldn't be respected if following the author's advice here.


Unless the game engine is doing its own scaling, this does sound like lying to the operating system to get out of the way of those pesky user-friendly features to get more frames.

I think Microsoft made it this hard to enable the DPI-aware setting exactly because it forces developers to think about things like DPI. If everyone follows this guide and ignores it, then I predict that in a few years this setting will be ignored as well and a new DPI-awareness API will be released.


If you’re DPI aware you should never size your elements by physical pixels, but many game UI elements like a HUD or very simple menus scale better using “percentage of screen dimension” or similar heuristics. Like using fixed device independent pixel sizes this system won’t cause the elements to look tiny on a HiDPI display, and it will generally do a better job on large screens that are usually far away from the user (e.g. TVs).


Games should either be aware of the user’s preferred scaling or at least offer their own UI scaling option. But they should always register as DPI aware so they don’t render the 3D scene at a lower resolution than what’s selected




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: