How to force Stretch viewport at integer scale

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By _sad_dog

As document says :

‘’ Godot currently doesn’t have a way to enforce integer scaling when using the canvas_items or viewport stretch mode, which means pixel art may look bad if the final window size is not a multiple of the base window size. To fix this, use an add-on such as the Integer Resolution Handler ‘’

godot currently does not support enforce integer scaling viewport, and then point out a plugin doing this job. The plugin GitHub - Yukitty/godot-addon-integer_resolution_handler: Integer Resolution Handler addon for Godot Engine do accomplish this job, but it does not work for 4.x as API changes a lot.

After searching through documents and source files, I still can’t find these APIs to do what I want, so I come here for help.

Okay, I find DisplayServer singleton just now, I think. I think i can do it by query screen size from DisplayServer and set ViewPort’s canvas_transform. Is it correct?

_sad_dog | 2022-12-23 17:56

Okay, I find that Camera2D will modify the viewport’s cavas_transform, and makes any change from other modification invalid, so what’s the proper way to do this?

_sad_dog | 2022-12-28 14:36

I finally found Window and Window.content_scale_factor to expand window

_sad_dog | 2022-12-28 15:52