# Line of Constant Width

Hi,

I’m trying to use openGL geometry to create a wiggly line, a little like you might see on a graph. Because I need the line to have a selectable width, I need to draw it with a quad or triangle strip. I’m basically drawing a straight line first, then displacing the vertices on the Y-axis with a GLSL shader. My problem is, the apparent width of the line changes with the slope of the line, so steeply-sloping lines appear very narrow. I assume I need to offset the position of each vertex according to the positions of neighbouring vertices, to compensate for this, so the line appears to have a constant width. Can anyone give me some pointers on how I might achieve this within my shader code? This is probably really basic stuff, but it’s a lonnnnnnng time since I did any trigonometry…

Cheers,

Old but still some useful information :
To sum up, either draw a dot at each joint, same diameter as line width, or fill using a mitered join, no need for trig here.

Ah, I see. That makes sense. I will look into that. There was a reason I wasn’t using GL lines though- I wanted the line-width to be modulated by an input texture, for an effect similar to a woodcut, and this wouldn’t be possible with an actual GLline, line.

a|x

There are two issues. ZbuffeR addressed one of them (the junctions of wide lines).

The other issue is the line width itself. For that, rather than have a displacement in only the Y axis as you have done, you need to calculate a displacement (equal to the desired width of the line) that is perpendicular to each line. (Alternatively, you could displace half the width to one side and the other half to the other side of the line to have the wide line centered on the line’s definition. This is especially good to do if you use circles at each junction.) Then you will draw a rectangle (not a parallelogram as simply offsetting the Y coordinates does) for each line.

Here’s a good resource for the geometric math for lines:
http://www.descarta2d.com/BookHTML/Chapters/lns.html

Incidentally, both of these tasks (junctions and line widths) are ideal tasks for the geometry shader. Look at the input layout qualifier “lines_adjacency” so that you can properly take into account the neighboring lines for each line you draw.