Does love.graphics.line draw a triangle?

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
skarph
Prole
Posts: 2
Joined: Sun Jun 21, 2020 1:05 am

Does love.graphics.line draw a triangle?

Post by skarph »

I've been experimenting with 3d graphics stuff using shaders, and i've made a fair amount of progress. Recently, I tried to give my 3d shapes an outline. I've tried to use love.graphics.setWireframe and then draw my shape on top of it (the lines were too thin), I've tried using love.graphics.line with 3 points (produced weird effects), and I naively tried using love.graphics.polygon with "line" instead of "fill" (produced even weirder effects).

Finally, I decided to draw a line using love.graphics.line for each side of the shape I'm trying to outline, only giving 2 points this time. This produces a triangle with a white-to-black gradient, which surprised me because I thought I was only passing 2 vertices to my shader instead of 3. Maybe I'm doing this wrong, but here's my explanation:

love.graphics.line doesn't actually draw lines, but triangles, where the 3rd vertex cannot be seen. Applying certain transformations to these 3 points can allow you to see this 3rd vertex, as openGL will attempt to interpolate between the two given vertices and this 3rd vertex.
triangle_line.love
(1.26 KiB) Downloaded 162 times
Personal theories aside, is there any way to draw a line that's immune from being transformed this way?

Thanks for any help you can give.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Does love.graphics.line draw a triangle?

Post by ReFreezed »

I don't have experience with 3D graphics, but here are some observations after some testing...
  • The gradient is from opaque white to transparent white - not to black.
  • Doing color.a=1; in the fragment shader gets rid of the gradient and makes the whole triangle opaque white.
  • Calling love.graphics.setLineStyle("rough") makes the triangle invisible.
I also did some testing to figure out how love.graphics.line() actually works and, as I suspected, single-segment lines are actually rectangles, i.e. two triangles or four vertices. With "rough" line style at least! With "smooth" line style there's one more wireframe line visible in the wireframe from the start of the drawn line to the end. You can also see a gradient effect even in the wireframe.
LÖVE lines.png
LÖVE lines.png (41.35 KiB) Viewed 2359 times
Anyway, to have full control over how your lines are drawn you should probably either draw rectangles or use your own meshes.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
Post Reply

Who is online

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