Why is viewport texture smaller than game screen ?

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

Hi,

I’m porting a hidden object game from Starling to Godot. In the game, I use screenshots quite a bit for transitions between levels.
I’m now looking at the Screen Capture tutorial for Godot 3.0, and I was wondering why this code :

var img = get_viewport().get_texture().get_data()
img.flip_y()

produces a screenshot that’s smaller than the game screen ? Also, why is the image flipped by default ?

https://postimg.cc/d7rLxfD9

I believe it’s based on the size of the monitor. If you maximize the screen it gives a different result. Just what I found.

ugly_cat | 2019-02-07 01:57

:bust_in_silhouette: Reply From: hammeron

The screenshot isn’t smaller than the game’s viewport. The TextureRect node that shows the screenshot is scaled down 0.5.

The image data is flipped because the underlying rendering API, OpenGL, assumes y coordinates from bottom to top but Godot 2D features use Y coordinates from top to bottom. If you capture a screenshot from memory managed by OpenGL, you have to flip it so it matches Godot coordinates system.

Thank you both for answering my question !

@hammeron : I totally overlooked the scaling property … And thank you for your explanation on OpenGL ! I hate not knowing ‘why’ =)

siska | 2019-02-10 08:19