0 votes

Hello,
I'm relatively new to Godot. I couldn't figure out how to draw a node on a texture.
For example, in my case, I try to draw a Polygon2Ds polygon on ImageTexture:

var tex = ImageTexture.new()
var poly: Polygon2D = $Polygon2D

# how to draw poly.polygon on tex ?

I know of draw_polygon, but that method draws on the game screen directly.
I need the texture in order to pass it to another node using textures.

in Engine by (19 points)

2 Answers

0 votes
Best answer

as @DigitalDrako led me to the right direction. This can be achieved by capturing textures via Viewports:
https://docs.godotengine.org/en/stable/tutorials/viewports/viewports.html#doc-viewports

by (19 points)
+1 vote

I think you want to make sure your polygon is a child of the texture. That way it shows up on top of the texture and it's connected to the texture

by (207 points)

How can I add a polygon to a texture as a child? As far as I can see the Texture class doesn't have any method to add a Node or alike. Or do you mean the texture's node?
But actually it's crucial that the polygon is actually drawn in the texture itself. To be more precise I need to use that texture as a mask texture having the shape of that polygon.

Hmm, I don't have a lot of experience with polygons. Tell me if one of these helps:
https://godotengine.org/qa/3169/mask-sprite-using-polygon
https://www.youtube.com/watch?v=phA51SdFXCs

I had already checked the latter but the first one seems promissing. I've also found out that there is the possibility to capture textures by Viewports, as it is also pointed out in one of the answers from the link you've shared: https://docs.godotengine.org/en/stable/tutorials/viewports/viewports.html#doc-viewports

thanks for your help!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.