Page 1 of 1

Does love.graphics.line draw a triangle?

Posted: Sun Jun 21, 2020 1:59 am
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 163 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.

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

Posted: Sun Jun 21, 2020 6:20 pm
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 2360 times
Anyway, to have full control over how your lines are drawn you should probably either draw rectangles or use your own meshes.