opengl 更改背景色问题
voidmyTest(){glBegin(GL_LINE_LOOP);glClearColor(1.0f,1.0f,0.0f,1.0f);//把背景色设置为白色,为什么会...
void myTest()
{
glBegin(GL_LINE_LOOP);
glClearColor(1.0f,1.0f,0.0f,1.0f); // 把背景色设置为白色,为什么会失败
glClear(GL_COLOR_BUFFER_BIT);// 背景色一直都是黑色~
glFlush();
glColor3f(1,1,0);
glVertex2f(0.0,0.0);
glVertex2f(0,0.8);
glVertex2f(-0.5,0.8);
glVertex2f(-0.5,-0.9);
glEnd();
glFlush();
}
int main( int argc,char * argv[] )
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(200,200);
glutCreateWindow("My OpenGL");
glutDisplayFunc(&myTest);
glutMainLoop();
return 0 ;
} 展开
{
glBegin(GL_LINE_LOOP);
glClearColor(1.0f,1.0f,0.0f,1.0f); // 把背景色设置为白色,为什么会失败
glClear(GL_COLOR_BUFFER_BIT);// 背景色一直都是黑色~
glFlush();
glColor3f(1,1,0);
glVertex2f(0.0,0.0);
glVertex2f(0,0.8);
glVertex2f(-0.5,0.8);
glVertex2f(-0.5,-0.9);
glEnd();
glFlush();
}
int main( int argc,char * argv[] )
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(200,200);
glutCreateWindow("My OpenGL");
glutDisplayFunc(&myTest);
glutMainLoop();
return 0 ;
} 展开
1个回答
展开全部
你的代码中对glBegin..glEnd的使用存在错误之处:
glBegin..glEnd这段代码中,仅允许执行部分命令,他们是 glVertex,glColor,glSecondaryColor,
glIndex,glNormal, glFogCoord,等等(完整列表参看: https://www.opengl.org/sdk/docs/man2/xhtml/glBegin.xml) 。你的glClearColor命令,并不包含列表内,因此你的代码是无效的,因而系统采用默认黑色背景。
更正后的代码为:
void myTest()
{
//设置背景颜色并清除颜色缓存
glClearColor(1.0f,1.0f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
//绘制折线
glBegin(GL_LINE_LOOP);
glColor3f(1,1,0);
glVertex2f(0.0,0.0);
glVertex2f(0,0.8);
glVertex2f(-0.5,0.8);
glVertex2f(-0.5,-0.9);
glEnd();
glFlush();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询