Opengl平滑着色问题 :我用Qt+Opengl(QWidget类),希望能够画一个平滑着色的三角形,但画出来是同一个颜glClearColor(0,0.5,1,1);glColor3f(0,0,0);glClear(GL_COLOR_BUFFER_BIT);glShadeModel(GL_FLAT);glEnable(GL_DEPTH_TEST);glE
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/27 13:58:22
![Opengl平滑着色问题 :我用Qt+Opengl(QWidget类),希望能够画一个平滑着色的三角形,但画出来是同一个颜glClearColor(0,0.5,1,1);glColor3f(0,0,0);glClear(GL_COLOR_BUFFER_BIT);glShadeModel(GL_FLAT);glEnable(GL_DEPTH_TEST);glE](/uploads/image/z/6292905-33-5.jpg?t=Opengl%E5%B9%B3%E6%BB%91%E7%9D%80%E8%89%B2%E9%97%AE%E9%A2%98+%3A%E6%88%91%E7%94%A8Qt%2BOpengl%EF%BC%88QWidget%E7%B1%BB%EF%BC%89%2C%E5%B8%8C%E6%9C%9B%E8%83%BD%E5%A4%9F%E7%94%BB%E4%B8%80%E4%B8%AA%E5%B9%B3%E6%BB%91%E7%9D%80%E8%89%B2%E7%9A%84%E4%B8%89%E8%A7%92%E5%BD%A2%2C%E4%BD%86%E7%94%BB%E5%87%BA%E6%9D%A5%E6%98%AF%E5%90%8C%E4%B8%80%E4%B8%AA%E9%A2%9CglClearColor%280%2C0.5%2C1%2C1%29%3BglColor3f%280%2C0%2C0%29%3BglClear%28GL_COLOR_BUFFER_BIT%29%3BglShadeModel%28GL_FLAT%29%3BglEnable%28GL_DEPTH_TEST%29%3BglE)
Opengl平滑着色问题 :我用Qt+Opengl(QWidget类),希望能够画一个平滑着色的三角形,但画出来是同一个颜glClearColor(0,0.5,1,1);glColor3f(0,0,0);glClear(GL_COLOR_BUFFER_BIT);glShadeModel(GL_FLAT);glEnable(GL_DEPTH_TEST);glE
Opengl平滑着色问题 :我用Qt+Opengl(QWidget类),希望能够画一个平滑着色的三角形,但画出来是同一个颜
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方法不对,单我该怎样改呢?
如果有人知道我会加满分~
Opengl平滑着色问题 :我用Qt+Opengl(QWidget类),希望能够画一个平滑着色的三角形,但画出来是同一个颜glClearColor(0,0.5,1,1);glColor3f(0,0,0);glClear(GL_COLOR_BUFFER_BIT);glShadeModel(GL_FLAT);glEnable(GL_DEPTH_TEST);glE
在glBegin(GL_TRIANGLES);之前加一句:glShadeModel(GL_SMOOTH);就可以了.
glShadeModel(GL_FLAT);这一句不要了.
有什么问题可以给我留言.