Page 1 of 1

Rendering issue with polygon

Posted: Thu Sep 26, 2019 4:28 am
by M3OW
So I'm trying to make some sort of message box with an arrow pointing to a square.

I'm using

Code: Select all

love.graphics.polygon
to render this. I'm rendering a rectangle-shaped polygon, and if some character were to be talking, then there would be more vertices to turn that rectangle into a speech bubble shape.

Image

Image

So in the bottom image, I clicked on the character on the right, the left part of the arrow is way off to the left, so I assumed my math was wrong. However, when I used the SAME vertices with

Code: Select all

love.graphics.points
, it works as intended

Image
Image

Image

Is there any caveat or something wrong with my implimenation of

Code: Select all

love.graphics.polygon

Re: Rendering issue with polygon

Posted: Thu Sep 26, 2019 5:01 am
by ivan
Your polygon is concave. love.graphics.polygon works with convex polygons only.
You could draw your speech bubble in two parts as a rectangle and a triangle or you could use love.math.triangulate
My tutorial on polygon math:
https://2dengine.com/?p=polygons#Convex_or_concave

Re: Rendering issue with polygon

Posted: Thu Sep 26, 2019 10:30 am
by pgimeno
Here's an example that creates a mesh out of a polygon and renders it: https://love2d.org/forums/viewtopic.php ... 64#p227964

If you only need a flat colour, you can probably simplify it by omitting the assignation of UVs.

Re: Rendering issue with polygon

Posted: Fri Sep 27, 2019 11:08 am
by M3OW
ivan wrote: Thu Sep 26, 2019 5:01 am Your polygon is concave. love.graphics.polygon works with convex polygons only.
You could draw your speech bubble in two parts as a rectangle and a triangle or you could use love.math.triangulate
My tutorial on polygon math:
https://2dengine.com/?p=polygons#Convex_or_concave
Thank you for your help. I solved this problem by using

Code: Select all

-- Doesn't work
-- return love.graphics.polygon('fill', verticies)

for _, triangle in love.math.triangulate(verticies) do
	 return love.graphics.polygon('fill', triangle)
end