mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Added the C# code equivalent to the note in Viewport.GetTexture()
Define 'viewport' for parity with GDScript's '$viewport' Co-authored-by: Paul Joannon <437025+paulloz@users.noreply.github.com>
This commit is contained in:
parent
e67074d0ab
commit
0ea06fe446
1 changed files with 14 additions and 4 deletions
|
@ -122,11 +122,21 @@
|
||||||
<description>
|
<description>
|
||||||
Returns the viewport's texture.
|
Returns the viewport's texture.
|
||||||
[b]Note:[/b] When trying to store the current texture (e.g. in a file), it might be completely black or outdated if used too early, especially when used in e.g. [method Node._ready]. To make sure the texture you get is correct, you can await [signal RenderingServer.frame_post_draw] signal.
|
[b]Note:[/b] When trying to store the current texture (e.g. in a file), it might be completely black or outdated if used too early, especially when used in e.g. [method Node._ready]. To make sure the texture you get is correct, you can await [signal RenderingServer.frame_post_draw] signal.
|
||||||
[codeblock]
|
[codeblocks]
|
||||||
|
[gdscript]
|
||||||
func _ready():
|
func _ready():
|
||||||
await RenderingServer.frame_post_draw
|
await RenderingServer.frame_post_draw
|
||||||
$Viewport.get_texture().get_image().save_png("user://Screenshot.png")
|
$Viewport.get_texture().get_image().save_png("user://Screenshot.png")
|
||||||
[/codeblock]
|
[/gdscript]
|
||||||
|
[csharp]
|
||||||
|
public async override void _Ready()
|
||||||
|
{
|
||||||
|
await ToSignal(RenderingServer.Singleton, RenderingServer.SignalName.FramePostDraw);
|
||||||
|
var viewport = GetNode<Viewport>("Viewport");
|
||||||
|
viewport.GetTexture().GetImage().SavePng("user://Screenshot.png");
|
||||||
|
}
|
||||||
|
[/csharp]
|
||||||
|
[/codeblocks]
|
||||||
[b]Note:[/b] When [member use_hdr_2d] is [code]true[/code] the returned texture will be an HDR image encoded in linear space.
|
[b]Note:[/b] When [member use_hdr_2d] is [code]true[/code] the returned texture will be an HDR image encoded in linear space.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue