What does DisplayServer.screen_get_scale() actually get?

Godot Version

4.4.1 stable

Question

I’m trying to calculate the true usable screen width translated into the world (on mobile).
I can successfully calculate it using:
DisplayServer.screen_get_usable_rect().end.x / camera.zoom.x * DisplayServer.screen_get_scale()

BUT if my screen is in portrait mode, using get_screen_scale throws the calculation off. So I have to use
DisplayServer.screen_get_usable_rect().end.x / camera.zoom.x

on my google pixel 4, screen_get_scale() returns the following values depending on the device orientation:
portrait: 1.35000002384186
landscape: 1.79999995231628

I assumed from the docs that it returned some value related to pixel density, but I suppose I am mistaken. I have two questions:

  1. What does DisplayServer.screen_get_scale() actually get?
  2. Why does my formula require me to ignore it if my phone is in portrait mode?

Looks like it takes the screen width and height also into account godot/platform/android/display_server_android.cpp at 4d7c448a0a58ff4b14d4a06c4b1bb387b58f4508 · godotengine/godot · GitHub which will change depending on orientation.

Not sure where the problem is though.

1 Like