mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-05 07:20:07 +01:00
-Fixed screen capture for viewports, added a screen capture demo, fixes #1529
This commit is contained in:
8
viewport/screen_capture/engine.cfg
Normal file
8
viewport/screen_capture/engine.cfg
Normal file
@@ -0,0 +1,8 @@
|
||||
[application]
|
||||
|
||||
name="Screen Capturing"
|
||||
main_scene="res://screen_capture.scn"
|
||||
|
||||
[display]
|
||||
|
||||
stretch_mode="2d"
|
||||
BIN
viewport/screen_capture/mountains.png
Normal file
BIN
viewport/screen_capture/mountains.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 906 KiB |
27
viewport/screen_capture/screen_capture.gd
Normal file
27
viewport/screen_capture/screen_capture.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
extends Control
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
func _ready():
|
||||
# Initialization here
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
func _on_button_pressed():
|
||||
get_viewport().queue_screen_capture()
|
||||
#let two frames pass to make sure the screen was aptured
|
||||
yield(get_tree(),"idle_frame")
|
||||
yield(get_tree(),"idle_frame")
|
||||
#retrieve the captured image
|
||||
var img = get_viewport().get_screen_capture()
|
||||
#create a texture for it
|
||||
var tex = ImageTexture.new()
|
||||
tex.create_from_image(img)
|
||||
#set it to the capture node
|
||||
get_node("capture").set_texture(tex)
|
||||
pass # replace with function body
|
||||
BIN
viewport/screen_capture/screen_capture.scn
Normal file
BIN
viewport/screen_capture/screen_capture.scn
Normal file
Binary file not shown.
Reference in New Issue
Block a user