Rendering issue with polygon

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
M3OW
Prole
Posts: 4
Joined: Fri Aug 08, 2014 3:47 pm

Rendering issue with polygon

Post 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
Attachments
bug.love
Unzip, and uncomment line 59 to see the issue I'm having
(1.02 KiB) Downloaded 105 times
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Rendering issue with polygon

Post 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
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Rendering issue with polygon

Post 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.
M3OW
Prole
Posts: 4
Joined: Fri Aug 08, 2014 3:47 pm

Re: Rendering issue with polygon

Post 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	 
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests