Godot Version
4.3
Question
I’m trying to create a custom Texture2D by drawing stuff on a canvas item, converting it to an image and creating the texture from the image
This is my current setup:
extends Sprite2D
var rs := RenderingServer
func _ready() -> void:
var ca: RID = rs.canvas_item_create()
rs.canvas_item_set_transform(ca, Transform2D.IDENTITY)
rs.canvas_item_add_rect(ca, Rect2(-100, -100, 200, 200), Color.RED)
rs.canvas_item_add_circle(ca, Vector2.ZERO, 100, Color.MAGENTA)
var img: Image = rs.texture_2d_get(ca)
print("Image: ", img)
texture = ImageTexture.create_from_image(img)
But when I run the script the sprite does not get a texture and the console prints:
Image: <Object#null>
So it looks like rs.texture_2d_get()
is not working at all and I have no idea why…
Please help me!
Thanks in advance!