OpenGL3D图形绘制

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值