OpenGL中的画线
有这么一段程序:voidCGfxOpenGL::Render(){floatlineWidth=0.5;glClear(GL_COLOR_BUFFER_BIT|GL_DE...
有这么一段程序:
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);
// draw a series of lines of increasing width with stippling
for (line = 0.0; line < 7.0; line+=0.5)
{
// set the line width
glLineWidth(lineWidth);
// draw the point
glBegin(GL_LINES);
glVertex3f(1.0f, 0.0f, line-3.0f);
glVertex3f(5.0f, 0.0f, line-3.0f);
glEnd();
// increase the point size for the next point
lineWidth += 1.0;
}
glDisable(GL_LINE_STIPPLE);
}
明明前面应该是画一系列的实线,为什么运行之后只过了几秒钟,它就变成跟后面一样是点划线了呢?
那应该怎么设置呢?才能让各自显示各自的图形呢? 展开
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);
// draw a series of lines of increasing width with stippling
for (line = 0.0; line < 7.0; line+=0.5)
{
// set the line width
glLineWidth(lineWidth);
// draw the point
glBegin(GL_LINES);
glVertex3f(1.0f, 0.0f, line-3.0f);
glVertex3f(5.0f, 0.0f, line-3.0f);
glEnd();
// increase the point size for the next point
lineWidth += 1.0;
}
glDisable(GL_LINE_STIPPLE);
}
明明前面应该是画一系列的实线,为什么运行之后只过了几秒钟,它就变成跟后面一样是点划线了呢?
那应该怎么设置呢?才能让各自显示各自的图形呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询