Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viewport size conflictingly doubled when using "Allow Hidpi" and stretch settings "2d" and "expand" #28666

Open
ghost opened this issue May 4, 2019 · 6 comments

Comments

@ghost
Copy link

ghost commented May 4, 2019

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:

  • The viewport size as reported by get_viewport().size
  • The size defined in the project settings file
  • The actual size of the viewport as calculated by the get_actual_viewport_size() function inside of InfoUI.gd
  • The position of the mouse
  • The position of a square that you can move around using the arrow keys or WASD

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:

  1. Create a Godot project with "Allow Hidpi" and stretch settings "2d" and "expand".
  2. Run the project.
  3. Notice that the viewport size is double the defined size and does not match the coordinate system used to position objects.

Minimal reproduction project: ViewportBugHidpiProject.zip
(This is the exact same project from issue #28665, except "Allow Hidpi" is checked in the project settings)

@LucidTaZ
Copy link

LucidTaZ commented Jun 5, 2019

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

@ghost
Copy link
Author

ghost commented Jun 5, 2019

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!

@LucidTaZ
Copy link

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

@KoBeWi
Copy link
Member

KoBeWi commented Dec 19, 2020

Seems fixed in 3.2.4 beta4
Comment if you can still reproduce.

@Guang1234567
Copy link

Seems fixed in 3.2.4 beta4
Comment if you can still reproduce.

GetViewport still not working in hidpi mode on godot 3.2.4 rc1

#45323 (comment)

@KoBeWi
Copy link
Member

KoBeWi commented Feb 9, 2021

So according to that comment this is a platform-specific issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants