Skip to content

Instantly share code, notes, and snippets.

@andrew-wilkes
Last active July 15, 2025 21:20
Show Gist options
  • Save andrew-wilkes/41a90e1f273c9196e10ad4fcc64ec913 to your computer and use it in GitHub Desktop.
Save andrew-wilkes/41a90e1f273c9196e10ad4fcc64ec913 to your computer and use it in GitHub Desktop.
Capture viewport to image in Godot
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