Home Game Development godot – How to take a screenshot beyond the viewport?

godot – How to take a screenshot beyond the viewport?

0
godot – How to take a screenshot beyond the viewport?

[ad_1]

I have a large level design & I’m trying to take a pixel perfect screen shot of a particular area and/or the entire map bound within a region like this:

enter image description here

The region can be changed in size and position so I used a ReferenceRect ( Green box in the image) node to manually change it

So far I’ve come up with this:

extends ReferenceRect

func capture_image():
    var viewport=get_viewport()
    viewport.set_size_override(true, Vector2(rect_size.x, rect_size.x * viewport.size.y / viewport.size.x ))
    
    var image = viewport.get_texture().get_data()
    image.flip_y()
    image.save_png("res://screenshot.png")
    print("Took Screenshot!")

func _unhandled_input(event):
    if event is InputEventKey: 
        if event.pressed and event.scancode == KEY_SPACE: # try pressing space twice
            capture_image()

This fits the entire game within the screen window but the image generated does not give a pixel perfect screenshot & the image size/resolution remains 1024 x 600 pixels as you can see:
enter image description here

I suspect the window size itself would have to be increased to fit the ReferenceRect in order to get a pixel perfect screenshot

So is it possible to achieve this?
A crude method would also work since this is purely for development stage

Note: I’m using godot v3.5

[ad_2]