GLfloat xtri;
GLfloat ytri;
GLfloat ztri;
int DrawGLScene(GLvoid) // 从这里开始进行所有的绘制
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 清除屏幕及深度缓存
glLoadIdentity(); // 重置模型观察矩阵
glTranslatef(-0.0f,0.0f,-6.0f); // 左移 1.5 单位,并移入屏幕 6.0
glRotatef(xtri,1.0f,0.0f,0.0f); // 绕Y轴旋转金字塔
glRotatef(ytri,0.0f,1.0f,0.0f); // 绕Y轴旋转金字塔
glRotatef(ztri,0.0f,0.0f,1.0f); // 绕Y轴旋转金字塔
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,-0.0f, 1.0f); // 三角形的左下顶点 (前侧面)
glColor3f(0.0f,0.0f,1.0f); // 蓝色
glVertex3f( 1.0f,-0.0f, 1.0f); // 三角形的右下顶点 (前侧面)
glColor3f(1.0f,0.0f,0.0f); // 红色
glVertex3f( 0.0f, 1.0f, 0.0f); // 三角形的上顶点 (右侧面)
glColor3f(0.0f,0.0f,1.0f); // 蓝色
glVertex3f( 1.0f,-0.0f, 1.0f); // 三角形的左下顶点 (右侧面)
glColor3f(0.0f,1.0f,0.0f); // 绿色
glVertex3f( 1.0f,-0.0f, -1.0f); // 三角形的右下顶点 (右侧面)
glColor3f(1.0f,0.0f,0.0f); // 红色
glVertex3f( 0.0f, 1.0f, 0.0f); // 三角形的上顶点 (后侧面)
glColor3f(0.0f,1.0f,0.0f); // 绿色
glVertex3f( 1.0f,-0.0f, -1.0f); // 三角形的左下顶点 (后侧面)
glColor3f(0.0f,0.0f,1.0f); // 蓝色
glVertex3f(-1.0f,-0.0f, -1.0f); // 三角形的右下顶点 (后侧面)
glColor3f(1.0f,0.0f,0.0f); // 红色
glVertex3f( 0.0f, 1.0f, 0.0f); // 三角形的上顶点 (左侧面)
glColor3f(0.0f,0.0f,1.0f); // 蓝色
glVertex3f(-1.0f,-0.0f,-1.0f); // 三角形的左下顶点 (左侧面)
glColor3f(0.0f,1.0f,0.0f); // 绿色
glVertex3f(-1.0f,-0.0f, 1.0f); // 三角形的右下顶点 (左侧面)
glEnd(); // 金字塔绘制结束
glBegin(GL_QUADS); // 开始绘制金字塔的底部
glColor3f(0.0f,1.0f,0.0f); // 绿色
glVertex3f(-1.0f, 0.0f,1.0f); // 四边形的右上顶点 (顶面)
glColor3f(0.0f,0.0f,1.0f); // 蓝色
glVertex3f(1.0f, 0.0f,1.0f); // 四边形的左上顶点 (顶面)
glColor3f(0.0f,1.0f,0.0f); // 绿色
glVertex3f(1.0f, 0.0f, -1.0f); // 四边形的左下顶点 (顶面)
glColor3f(0.0f,0.0f,1.0f); // 蓝色
glVertex3f( -1.0f, 0.0f, -1.0f); // 四边形的右下顶点 (顶面)
glEnd();
xtri+=0.8f;
ytri+=0.5f;
ztri+=0.9f;
return TRUE; // 一切 OK
}
转载于:https://www.cnblogs.com/tiandsp/archive/2012/01/23/2329026.html