next up previous contents
Next: 15.7 Painting on Images Up: 15.6 2D Drawing Techniques Previous: 15.6 2D Drawing Techniques   Contents

15.6.1 Line Joins

Wide lines in OpenGL are drawn by expanding the width of the line along the $x$ or $y$ direction of the line for $y$-major and $x$-major lines, respectively (a line is $x$-major if the slope is in the range $[-1,1]$). When two non-colinear wide lines are connected together the overlap in the end caps leaves a noticeable gap. In 2D drawing engines such as GDI or the X Window System, lines can be joined using a number of different styles: round, mitered, or beveled as shown in Figure 86.


% latex2html id marker 17823
\fbox{\begin{tabular}{c}
\vrule width 0pt height 0....
...gure \thefigure . Line Join Styles: None, Round, Miter, Bevel}\\
\end{tabular}}

A round join can be implemented by drawing a round antialiased point with a size equal to the line width at the shared vertex. For most implementations the antialiasing algorithm generates a point that is similar enough in size to match the line width without noticeable artifacts. However, many implementations do not support large antialiased point sizes, making it necessary to use a triangle fan or texture mapped quadrilateral to implement a disc of the desired radius to join very wide lines.

A mitered join can be implemented by drawing a triangle fan with the first vertex at the shared vertex of the join, and three remaining vertices at the two outside vertices of rectangles enclosing the two lines, and the intersection point of the two outside edges of the wide lines extended until they meet. For an $x$-major line of width $w$ and window coordinate end points $(x_{0}, y_{0})$ and $(x_{1}, y_{1})$ the rectangle around the line is $(x_{0}, y_{0}-(w-1)/2)$, $(x_{0}, y_{0}-(w-1)/2+w)$, $(x_{1}, y_{1}-(w-1)/2+w)$, $(x_{1}, y_{1}-(w-1)/2)$.

Mitered joins with very sharp angles are not aesthetically pleasing, so for angles less then some threshold angle (typically 11 degrees) a bevel join is used. A bevel join can be constructed by rendering a single triangle consisting of the shared vertex and the two outside corner vertices of the lines as described above.

Having gone this far, it is a small step to switch from using lines to using triangle strips to draw the lines instead. One advantage of using lines is that many OpenGL implementations support antialiasing up to moderate line widths, whereas there is substantially less support for polygon antialiasing. Wide antialiased lines can be combined with antialiased points to do round joins, but requires the overlap algorithm from Section 7.5 to sort the coverage values. Accumulation buffer antialiasing can be used with triangle primitives as well.


next up previous contents
Next: 15.7 Painting on Images Up: 15.6 2D Drawing Techniques Previous: 15.6 2D Drawing Techniques   Contents
2001-01-10