Godot version: v3.1.stable.official
OS: macOS Mojave 10.14.4
Device: 13" 2017 MacBook Pro w/ 4 Thunderbolt 3 Ports
GPU: Intel Iris Plus Graphics 650
Display: 2560x1600 Retina
Issue description:
This is sort of related to issue #28665, but I figured this issue was different enough to post separately.
When using "Allow Hidpi" and stretch settings "2d" and "expand", the viewport size returned by get_viewport().size is always double the size defined in the project settings file. However, the mouse position and objects in the scene are positioned using the non-doubled size. For example, placing an object at get_viewport().size.x would move it completely out of view of the window, however placing it at get_viewport().size.x / 2.0 would properly place it on the right edge of the window.
I'm not sure whether this is intended or not, but I find this behavior odd as it appears that objects in the scene are not positioned using the Hidpi setting.
The attached minimal reproduction project displays the following values to highlight the discrepancies between them:
Notice how the positions of the mouse and square when moving them to the right or bottom edges of the window do not match the width/height reported by get_viewport().size.
Steps to reproduce:
Minimal reproduction project: ViewportBugHidpiProject.zip
(This is the exact same project from issue #28665, except "Allow Hidpi" is checked in the project settings)
I'm having the same issue in Godot 3.1.1-stable.official.
My use case: a custom tooltip-like window that follows the mouse, but has to stay inside the screen so it's clamped using the viewport size. Using HiDpi all my mouse position measures are still relative to the "test size" but the viewport size is doubled, breaking the use case. I haven't found any way to solve this so it seems like a bug to me, or a missing "get viewport scale factor" feature.
By the way, this use case is also affected by the #28665 issue.
Also my system specs, to add more information on the issue:
OS: macOS Mojave 10.14.5
Device: MacBook Pro (Retina, 15-inch, Mid 2015)
GPU: Intel Iris Pro 1536 MB
Display: 2880x1800 Retina
Thanks for your input, @LucidTaZ! If you're still looking for a workaround, I wrote a small function in the attached project that calculates the actual size of the viewport. I'll paste it here for convenience (I also added some additional static typing):
extends Node
var defined_size: Vector2
func _ready() -> void:
var width: int = ProjectSettings.get_setting("display/window/size/width")
var height: int = ProjectSettings.get_setting("display/window/size/height")
defined_size = Vector2(width, height)
func get_actual_viewport_size() -> Vector2:
var viewport_size := get_viewport().size
var scale := viewport_size / defined_size
var actual_size := defined_size
if scale.x > scale.y:
actual_size.x = defined_size.y * (viewport_size.x / viewport_size.y)
elif scale.y > scale.x:
actual_size.y = defined_size.x * (viewport_size.y / viewport_size.x)
return actual_size
This would work well in a singleton (AutoLoad) script so it can be accessed from anywhere. Hope this helps!
Actually I just tried out your minimal reproduction project but compared the values to get_viewport().get_visible_rect().size and it seems this is what you need. I've successfully tested this in Godot 3.1.2.stable.official and v3.2.stable.official.
Here's your modified example:
ViewportBugHidpiProject.zip
Most helpful comment
Thanks for your input, @LucidTaZ! If you're still looking for a workaround, I wrote a small function in the attached project that calculates the actual size of the viewport. I'll paste it here for convenience (I also added some additional static typing):
This would work well in a singleton (AutoLoad) script so it can be accessed from anywhere. Hope this helps!