#include<stdlib.h>
#include<GL/glut.h>
GLfloat vertices[][3]={{-1.0,-1.0,1.0},{-1.0,1.0,1.0},{1.0,1.0,1.0},{1.0,-1.0,1.0},{-1.0,-1.0,-1.0},{-1.0,1.0,-1.0},{1.0,1.0,-1.0},{1.0,-1.0,-1.0}};
GLfloat colors[][3]={{1.0,0.0,0.0},{0.0,1.0,1.0},{1.0,1.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0},{1.0,0.0,1.0},{0.0,0.0,0.0},{1.0,1.0,1.0}};
void polygon(int a,int b,int c,int d)
{
glShadeModel(GL_FLAT);
glBegin(GL_POLYGON);
glColor3fv(colors[a]);
glTexCoord2f(0.0,0.0);
glVertex3fv(vertices[a]);
glColor3fv(colors[b]);
glTexCoord2f(0.0,1.0);
glVertex3fv(vertices[b]);
glColor3fv(colors[c]);
glTexCoord2f(1.0,1.0);
glVertex3fv(vertices[c]);
glColor3fv(colors[d]);
glTexCoord2f(1.0,0.0);
glVertex3fv(vertices[d]);
glEnd();
}
void colorcube()
{
polygon(0,3,2,1);
polygon(2,3,7,6);
polygon(3,0,4,7);
polygon(1,2,6,5);
polygon(4,5,6,7);
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余3页未读,立即下载