//三维
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5, 0.0, -6.0);
glRotatef(rTri, 0.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
//前侧面
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-1.0, -1.0, 1.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
//右侧面
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(1.0, -1.0, 1.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(1.0, -1.0, -1.0);
//后侧面
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(1.0, -1.0, -1.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(-1.0, -1.0, -1.0);
//左侧面
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(-1.0, -1.0, -1.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-1.0, -1.0, 1.0);
glEnd();
rTri += 1.2;
//底面
glBegin(GL_QUADS);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(1.0, -1.0, 1.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(1.0, -1.0, -1.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(-1.0, -1.0, -1.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-1.0, -1.0, 1.0);
glEnd();
//立方体
glLoadIdentity();
glTranslatef(1.5, 0.0, -7.0);
glRotatef(rQuad,1.0,1.0,1.0);
#define f1 1.0, 1.0, 1.0
#define f2 -1.0, 1.0, 1.0
#define f3 -1.0, -1.0, 1.0
#define f4 1.0, -1.0, 1.0
#define b1 -1.0, 1.0, -1.0
#define b2 1.0, 1.0, -1.0
#define b3 1.0, -1.0, -1.0
#define b4 -1.0, -1.0, -1.0
glBegin(GL_QUADS);
//正侧面
glColor3f(1.0, 0.0, 0.0);
glVertex3f(f1);
glVertex3f(f2);
glVertex3f(f3);
glVertex3f(f4);
void setpoint(int o1, int p1, int q1,
int o2, int p2, int q2,
int o3, int p3, int q3,
int o4, int p4, int q4);
//右侧面
glColor3f(1.0,0.5, 0.0);
setpoint(b2, f1, f4, b3);//其实就是按顺序glVertex3f()四个点
//后侧面
glColor3f(0.0, 1.0, 1.0);
setpoint(b1, b2, b3, b4);
//左侧面
glColor3f(0.0, 0.5, 1.0);
setpoint(f2, b1, b4, f3);
//上底面面
glColor3f(0.0, 0.0, 1.0);
setpoint(b2, b1, f2, f1);
//下底面
glColor3f(0.0, 1.0, 0.0);
setpoint(b4, b3, f4, f3);
glEnd();
rQuad -= 1.0;
还是修改paintGL()三维就是把立方体的几个面都画出来,画面的时候注意逆时针开始画(画的顺序要一致),面的连接点要注意一致