计算机图形学（三）_图元的属性_7_ 线属性函数

16-08-23        来源：[db:作者]

OpenGL线宽函数

` glLineWidth (width);`

OpenGL的线宽函数用4.5节的方法实现。即通过比较线段端点的水平和垂直距离Δx和Δy来确定使用垂直段或水平段来生成粗线段。

OpenGL线型函数

`glLineStripple(repeatFactor，pattern);`

` glEnable(GL_LINE_STIPPLE);`

`  glDisable(GL_LINE_STIPPLE);`

```/* Define a two-dimensional world-coordinate data type. */
typedef struct { float x, y; } wcPt2D;
wcPt2D dataPts [5];
void linePlot (wcPt2D dataPts [5])
{
int k;
glBegin (GL_LINE_STRIP);
for (k = 0; k < 5; k++)
glVertex2f (dataPts [k].x, dataPts [k].y);
glFlush ();
glEnd ();
}

/*Invoke a procedure here to draw coordinate axes. */
glEnable (GL_LINE_STIPPLE);

/* Input first set of (x, y) data values. */
glLineStipple (1, 0x1C47); // Plot a dash-dot, standard-width polyline.
linePlot (dataPts);

/* Input second set of (x, y) data values. */
glLineStipple (1, 0x00FF); // Plot a dashed, double-width polyline.
glLineWidth (2.0);
linePlot (dataPts);

/* Input third set of (x, y) data values. */
glLineStipple (1, 0x0101); // Plot a dotted, triple-width polyline.
glLineWidth (3.0);
linePlot (dataPts);

glDisable (GL_LINE_STIPPLE);```