#include <gl/glut.h>
/*glShadeModel( GLenum mode )可以设置的着色模型有:GL_SMOOTH和GL_FLAT
GL_FLAT单调着色:对点,直线或多边形采用一种颜色进行绘制,整个图元的颜色就是它的任何一点的颜色。
GL_SMOOTH平滑着色:用多种颜色进行绘制,每个顶点都是单独进行处理的,各顶点和各图元之间采用均匀插值。
*/
void Initial(void)
{
glClearColor(0.0,0.0,0.0,1.0);
glShadeModel(GL_SMOOTH);
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.0,0.0,0.0);glVertex2f(0.5,0.5);
glColor3f(0.0,1.0,0.0);glVertex2f(0.5,-0.5);
glColor3f(0.0,0.0,1.0);glVertex2f(-0.5,0.5);
glEnd();
glutSwapBuffers();
}
void myKeyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 's':
glShadeModel(GL_SMOOTH);
break;
case 'f':
glShadeModel(GL_FLAT);
break;
default:
break;
}
glutPostRedisplay();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(400,300);
glutInitWindowPosition(100,100);
glutCreateWindow("ShadeModel");
glutDisplayFunc(myDisplay);
glutKeyboardFunc(myKeyboard);
Initial();
glutMainLoop();
return 0;
}
glShadeMdel()中GL_FLAT与GL_SMMOTH的区别
最新推荐文章于 2021-06-08 20:44:04 发布