newMesh and polygons

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
mariofutire
Prole
Posts: 15
Joined: Sat Jul 26, 2014 7:28 pm

newMesh and polygons

Post by mariofutire »

Hi,

I was wondering if it is possible to use newMesh to draw

1) lines
and
2) polygons

The only "MeshDrawModes" available are for triangles.

When the polygons are filled with a texture it does not really make any difference whether they are many triangles or a single polygon, but for lines (like wireframe) or unfilled polygons it does.

Cheers
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: newMesh and polygons

Post by pgimeno »

(Antialiased) lines, no. Polygons, yes, with a bit of effort; see love.math.triangulate.
mariofutire
Prole
Posts: 15
Joined: Sat Jul 26, 2014 7:28 pm

Re: newMesh and polygons

Post by mariofutire »

And aliased lines?

Is this a limitation of newMesh or of OpenGL?
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: newMesh and polygons

Post by pgimeno »

I don't know if there's another way, maybe someone else wants to weigh in, but for aliased lines, I guess you can make every line a thin rectangle.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: newMesh and polygons

Post by raidho36 »

LOVE renders its default anti-aliased lines by creating a mesh in a shape of a line, with solid quadrilateral core and solid-to-transparent gradient colored 1-pixel padding to create an anti-aliased look without actually using hardware anti-aliasing (which is usually disabled in 2d). You can render lines in a batch by simply rendering rectangles but these will not have anti-aliasing, or you can render rectangles with gradient transparency at the edges to give them anti-aliased look. That said, love version 11 and higher should be able to auto-batch the rendering of built-in lines.

OpenGL doesn't support drawing lines. It does however supports drawing wireframe geometry, but that's only good for mesh debugging purposes.
mariofutire
Prole
Posts: 15
Joined: Sat Jul 26, 2014 7:28 pm

Re: newMesh and polygons

Post by mariofutire »

I have tried something as trivial as adding 3 new mesh draw modes
(see https://bitbucket.org/audetto/love/comm ... 372271c29a)

and it does behave as expected.

Moreover adding

Code: Select all

glLineWidth(2);
glEnable(GL_LINE_SMOOTH);
in Graphics::draw() allows to change the size. (this is not in the code linked above)

Got no idea how many more things I broke, but it looks something OpenGL would easily handle out of the box.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: newMesh and polygons

Post by slime »

Variable width line primitives aren't something modern GPUs have hardware for anymore, and modern OpenGL versions (which love uses when the graphics driver supports them) have deprecated glLineWidth and will cause an OpenGL error to be produced if you call it. GL_LINE_SMOOTH is also something GPUs don't have hardware for, and it isn't supported by modern GL versions either.

Aside from only supporting 1 pixel width lines on modern systems, OpenGL lines also have inconsistent implementations on different drivers in general. There are good reasons why love.graphics.line and friends moved away from GL_LINES and have a custom geometry-based implementation instead. :)


In terms of the most efficient way to draw lots of static lines, it depends a bit on your use-case but if love.graphics.line/polygon is too slow, either a custom Mesh or Spritebatch with an image scaled to look like a line, or a Canvas that has love.graphics.line primitives pre-drawn to it, are a couple decent alternatives.
mariofutire
Prole
Posts: 15
Joined: Sat Jul 26, 2014 7:28 pm

Re: newMesh and polygons

Post by mariofutire »

I am trying to draw 3d shapes with a custom shader applying a perspective transformation.
I am not sure how this would work with love.graphics.line / polygon.

Probably the only solution is to draw a thin parallelepiped or a non-culled set of triangles.

I can read elsewhere of the issues around GL_LINES and for a better rendering they should be avoided. "Lines" don't really exist in the real world anyway.

On the other hand, it might be useful at times to have a super simple (maybe not pixel perfect, but working) way to draw lines, a bit like a wireframe feature.
A bit like it happens for "points"?
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: newMesh and polygons

Post by slime »

There is love.graphics.setWireframe, which toggles a wireframe mode for anything drawn when it's enabled. As the wiki page mentions though, it doesn't work on mobile devices.
mariofutire
Prole
Posts: 15
Joined: Sat Jul 26, 2014 7:28 pm

Re: newMesh and polygons

Post by mariofutire »

So I guess this means there is no interest to add support for GL_LINES.
They can be useful to draw directions, normals without having to create half a dozen of triangles...
Post Reply

Who is online

Users browsing this forum: No registered users and 118 guests