OpenGL中的画线

来源:百度知道 编辑:UC知道 时间:2024/06/08 16:18:17
有这么一段程序:
void CGfxOpenGL::Render()
{
float lineWidth = 0.5;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear screen and depth buffer
glLoadIdentity();
gluLookAt(0.0, 10.0, 0.1, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

float line;
// draw a series of lines of increasing width
for (line = 0.0; line < 7.0; line+=0.5)
{
// set the line width
glLineWidth(lineWidth);

// draw the line
glBegin(GL_LINES);
glVertex3f(-5.0, 0.0, line-3.0f);
glVertex3f(-1.0, 0.0, line-3.0f);
glEnd();

// increase the line width for the next point
lineWidth += 1.0;
}

// reset line width
lineWidth = 0.5;

// enable stippling
glEnable(GL_LINE_STIPPLE);

// 0xAAAA = 1010 1010 1010 1010
short stipplePattern = 0xAAAA;

// set the stipple pattern
glLineStipple(2, stipplePattern);

//

开始时,默认下是采用实线模式的,所以前面开始是实线,后面你启用了点划模式,所以后面是点划线,OpenGL保留了这个状态,经过glutMainLoop后,重画,采用的点划线的方式,所以前面的直线也是点划线了