Why is there a discrepancy between the display size and the window size?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bitbloom
:warning: Old Version Published before Godot 3 was released.

This is more of a rhetorical question, but I wanted to throw it out there in case anyone came across this issue. If you set Allow Hidpi to on and have a HiDPI screen, then you will end up with a viewport that is larger than you expect.

If you use the following code, you get set the size of the window to the actual pixel values of the width and height which you set in your Project Settings.

# HiDPI Window Downscaling
var displaySize = Vector2(Globals.get("display/width"), Globals.get("display/height"))
var scaleFactor = OS.get_window_size() / displaySize
OS.set_window_size(displaySize / scaleFactor)

Of course, I wouldn’t recommend this because your game, since it’s pixel for pixel, will look comparatively tiny. However, the scaleFactor variable could be useful information for loading in higher resolution graphics on HiDPI displays.

I’m new to Godot, but so far I think this is the best way to deal with this. You could disallow hidpi or allow it and then set the stretch mode to 2d / viewport, but neither of those methods take full advantage of a HiDPI display.