draw_polygon() with uv doesn't work (for me?)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By argento

I need to draw a part of an image, delimited by a polygon, on the screen, but when I try to call CanvasItem.draw_polygon() with the uv array nothing will appear on screen.

I know that I can do it with a Polygon2D instance but I need to use the draw_polygon() function because I have a scripted node with custom drawing.

Here is a code example that doesn’t work for me

extends Node2D

var polygon: PoolVector2Array
var colors: PoolColorArray = PoolColorArray()
var uvs: PoolVector2Array = PoolVector2Array()
var external_texture:Texture = load("res://icon.png")

func _ready():
	polygon = PoolVector2Array([
	Vector2(64,64),
	Vector2(0,64),
	Vector2(0,0),
	Vector2(64,0)])
	
	for i in range(polygon.size()):
		colors.append(Color(1,1,1,1))

func _draw():
	draw_polygon(polygon, colors, polygon, external_texture)

I used 2 times the same PoolVector2Array, one for the polygon and the other for the uv

If i simply call draw_polygon(polygon, colors) without uv and texture information the polygon is drawn correctly (but in a solid color instead that with the texture)

I am using Godot 3.1 beta6

UV range is >=0 and <1 unless you’ve a repeating texture. So normalize your UVs. (here: divide by 64)

wombatstampede | 2019-02-23 20:34

Thank you very much, it worked

argento | 2019-02-23 20:55

:bust_in_silhouette: Reply From: wombatstampede

(Just putting the comment as answer so this Question is seen as answered.)

UV range is >=0 and <1 unless you’ve a repeating texture. So normalize your UVs. (here: divide by 64)