PDA

View Full Version : Best way to convert line into triangle strip



canurabus
02-12-2012, 09:09 PM
Hiya,

Is there an accepted best/most efficient algorithm to convert a line into a triangle strip? My reason for asking is that I'd like a to draw a 3d polyline with a specified thickness as efficiently as possible. The default opengl line primitive is limited to a thickness of 10 pixels, which isn't okay for my particular application.


Regards,

Pris

mhagain
02-13-2012, 03:05 AM
If you want to draw it as efficiently as possible don't convert to a triangle strip - convert to indexed triangles instead.

tksuoran
02-13-2012, 03:07 AM
A while back I implemented wide lines using a geometry shader. Geometry shader does clipping and viewport transformation and creates a quad / two triangles surrounding each line primitive. Fragment shader computes distance to line segment from the fragment and outputs alpha for line end rounding: Enable alpha to coverage and you will get nice round line ends.

http://neure.ath.cx/wideline.html

canurabus
02-13-2012, 12:33 PM
Thank you to both for the input.

mhagain -- I'll do this, thanks.

tksuoran -- the example's helpful, but I don't think using geo/fragment shaders is a good idea for my use case. I want cross platform support to maintain compatibility with older versions of OpenGL/ES.

I was mainly looking for an efficient way to take a poly line made up of point data like so,

http://www.nicoptere.net/biga/jointhedots_2.png

And adding a uniform thickness to it, then converting it to standard primitives that would render quickly.

MaxH
02-13-2012, 04:34 PM
You can start by replacing each line segment with a rectangle of your desired thickness. Since you want very thick lines, this will leave you cracks at the vertices. Is that o.k.? Have you thought about what you want the vertices to look like once they are connected by thick lines?

canurabus
02-14-2012, 04:19 PM
Hi MaxH,

Thanks for the reply. I'm trying to draw roads using their centerline and a given width parameter. The roads need to be a solid (don't necessarily need a thickness, but they need to be filled in). The first step I've taken is offsetting a given centerline based on the normal to a line segment in the polyline. Here's the result rendered as a GL_LINE_STRIP for clarity:

http://i.imgur.com/kkkfw.png

So now I'd like to convert that into a set of triangles, or a triangle strip, or whatever primitive will let me give the surface a color or texture, as efficiently as possible. I'm not really sure how to do that though.

* The uneven width in the image is an artifact due to some precision issues I introduced -- the lines are calculated to preserve the same width throughout.