Last active
July 15, 2025 21:20
-
-
Save andrew-wilkes/41a90e1f273c9196e10ad4fcc64ec913 to your computer and use it in GitHub Desktop.
Capture viewport to image in Godot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
func _ready(): | |
yield(VisualServer, "frame_post_draw") | |
var img = $ViewportContainer/Viewport.get_texture().get_data() | |
img.flip_y() | |
img.save_png("vp_image.png") | |
img = $VP3D/Viewport.get_texture().get_data() | |
img.convert(Image.FORMAT_RGBA8) # Retain the transparency | |
img.flip_y() | |
img.save_png("vp_image.png") | |
update() # This causes the _draw() function to run | |
func _draw(): | |
# Put statements here to draw to the canvas | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment