opengl20面体#include#defineX.525731112119133606#defineZ.850650808352039932staticGLfloatvdata[12][3]={//各顶点坐标{-X,0.0,Z},{X,0.0,Z},{-X,0.0,-Z},{X,0.0,-Z},{0.0,Z,X},{0.0,Z,-X},{0.0,-Z,X},{0.0,-Z,-X},{Z,X,0.0},{-Z,X,0.0},{Z,-X,0.0},{-Z,-X,0.0},};staticGLuinttindices[20][3]={//构成各面(三角形)的顶点索引{1,4,0},{4,9,0},{4,5,9},{8,5,4},{1,8,4},{1,10,8},{10,3,8},{8,3,5},{3,2,5},{3,7,2},{3,10,7},{10,6,7},{6,11,7},{6,0,11},{6,1,0},{10,1,6},{11,0,9},{2,11,9},{5,2,9},{11,2,7},};voiddisplay(){glClear(GL_COLOR_BUFFER_BIT);glBegin(GL_TRIANGLES);for(inti=0;i<20;++i){glColor3f(1.0,1.0,i*1.0/20);//颜色设置glVertex3fv(&vdata;[tindices[i][0]][0]);glVertex3fv(&vdata;[tindices[i][1]][0]);glVertex3fv(&vdata;[tindices[i][2]][0]);}glEnd();glFlush();}voidinit(){glClearColor(0.0,0.0,0.0,0.0);}intmain(intargc,char**argv){glutInit(&argc;,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(250,250);glutInitWindowPosition(100,100);glutCreateWindow("Polygon");init();glutDisplayFunc(display);glutMainLoop();return0;}
1