godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.91k stars 21.14k forks source link

Mouse Input coordinates are wrong in fullscreen when hiDPI mode is enabled #64705

Closed BigZaphod closed 2 years ago

BigZaphod commented 2 years ago

Godot version

v3.5.stable.official [991bb6ac7]

System information

macOS 12.5.1 (21G83), Apple M1 Max MacBook Pro

Issue description

I was attempting to implement a simple dragging mechanic and noticed it worked fine in windowed mode but the mouse input coordinates went all wrong after making the game window fullscreen. Here's a video showing what happens on my machine when I run the attached sample project:

https://user-images.githubusercontent.com/453721/185809093-d823fbaf-c6f6-4f0a-8c3d-72d5e186005f.mov

Steps to reproduce

Run the attached project on macOS (no idea if this also happens on Windows) and then click and drag from the Godot icon. It should drag out a smaller godot icon that follows the mouse around and disappears when you let go of the button.

If I disable the "Allow hiDPI" project setting, then it appears to work fine in fullscreen.

Minimal reproduction project

Godot HighDPI Input Bug.zip

Calinou commented 2 years ago

Duplicate of https://github.com/godotengine/godot/issues/34805.

The project uses the 2d stretch mode, so you likely need to multiply/divide mouse coordinates by the automatically determined scale factor.

Calinou commented 2 years ago

You likely need to multiply/divide mouse coordinates by the automatically determined scale factor, like this:

Godot HighDPI Input Bug.2.zip

BigZaphod commented 2 years ago

Duplicate of #34805.

The project uses the 2d stretch mode, so you likely need to multiply/divide mouse coordinates by the automatically determined scale factor.

I appreciate the workaround, but why in the world should game code have to do this? Isn't handling this kind of stuff exactly what using an engine is for?

Calinou commented 2 years ago

I appreciate the workaround, but why in the world should game code have to do this? Isn't handling this kind of stuff exactly what using an engine is for?

There are likely some cases where having the unscaled mouse coordinates is useful, but I don't know which ones exactly. Scaling mouse coordinates automatically would also break all projects that rely on the current coordinate system, so this can only be considered for 4.0.