View Full Version : Best way to convert line into triangle strip
02-12-2012, 08:09 PM
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.
02-13-2012, 02:05 AM
If you want to draw it as efficiently as possible don't convert to a triangle strip - convert to indexed triangles instead.
02-13-2012, 02: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.
02-13-2012, 11:33 AM
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,
And adding a uniform thickness to it, then converting it to standard primitives that would render quickly.
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?
02-14-2012, 03:19 PM
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:
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.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.