Opengl平滑着色问题 :我用Qt+Opengl(QWidget类),希望能够画一个平滑着色的三角形,但画出来是同一个颜
glClearColor(0,0.5,1,1);glColor3f(0,0,0);glClear(GL_COLOR_BUFFER_BIT);glShadeModel(GL...
glClearColor(0,0.5,1,1);
glColor3f(0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LEQUAL);
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 清除屏幕及深度缓存
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f); // 设置当前色为蓝色
glVertex3f( 1.0f,-1.0f, 0.0f); // 右下
glEnd(); // 三角形绘制结束
glTranslatef(3.0f,0.0f,0.0f); // 右移3单位
glColor3f(0.5f,0.5f,1.0f); // 一次性将当前色设置为蓝色
}
但画出来的是蓝色的三角形,而不是彩色的~~!
我人为是initialize方法不对,单我该怎样改呢??
如果有人知道我会加满分~~ 展开
glColor3f(0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LEQUAL);
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 清除屏幕及深度缓存
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f); // 设置当前色为蓝色
glVertex3f( 1.0f,-1.0f, 0.0f); // 右下
glEnd(); // 三角形绘制结束
glTranslatef(3.0f,0.0f,0.0f); // 右移3单位
glColor3f(0.5f,0.5f,1.0f); // 一次性将当前色设置为蓝色
}
但画出来的是蓝色的三角形,而不是彩色的~~!
我人为是initialize方法不对,单我该怎样改呢??
如果有人知道我会加满分~~ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询