学习OpenGL总结三

时间:2022-09-12 20:03:47
  • 学习OpenGL总结三
  • DrawGLScene_3D.h  内容如下:
  • //#include "DrawGLScene_3D.h"
  • #pragma once
  • //modify date:2009-01-08   vp:hsg
  • //#include <windows.h> // Windows的头文件
  • #include <stdio.h> // 标准输入/输出库的头文件 ( 新增 )
  • #include "OpenGL_FirstWin32.h"
  • //定义贴图OpenGL框架类
  • class OpenGLFrameWork_3D :public OpenGLFrameWork
  • {
  •     public:
  •         int DrawGLScene();
  •         int DrawGLScene_3D(GLvoid);
  • };
  • //实现方法
  • int OpenGLFrameWork_3D::DrawGLScene()
  • {
  •     return this->DrawGLScene_3D();
  • };
  • //第五课内容  向3D进军
  • int OpenGLFrameWork_3D::DrawGLScene_3D(GLvoid) // 此过程中包括所有的绘制代码
  • {
  •     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 清除屏幕及深度缓存
  •     glLoadIdentity(); // 重置模型观察矩阵
  •     glTranslatef(-1.5f,0.0f,-6.0f); // 左移 1.5 单位,并移入屏幕 6.0
  •     glRotatef(rtri,0.0f,1.0f,0.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,-1.0f, 1.0f); // 三角形的左下顶点 (前侧面)
  •     glColor3f(0.0f,0.0f,1.0f); // 蓝色
  •     glVertex3f( 1.0f,-1.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,-1.0f, 1.0f); // 三角形的左下顶点 (右侧面)
  •     glColor3f(0.0f,1.0f,0.0f); // 绿色
  •     glVertex3f( 1.0f,-1.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,-1.0f, -1.0f); // 三角形的左下顶点 (后侧面)
  •     glColor3f(0.0f,0.0f,1.0f); // 蓝色
  •     glVertex3f(-1.0f,-1.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,-1.0f,-1.0f); // 三角形的左下顶点 (左侧面)
  •     glColor3f(0.0f,1.0f,0.0f); // 绿色
  •     glVertex3f(-1.0f,-1.0f, 1.0f); // 三角形的右下顶点 (左侧面)
  •     glEnd(); //金字塔绘制结束
  •     glLoadIdentity();
  •     glTranslatef(1.5f,0.0f,-7.0f); // 先右移再移入屏幕
  •     glRotatef(rquad,1.0f,1.0f,1.0f); // 在XYZ轴上旋转立方体
  •     glBegin(GL_QUADS); // 开始绘制立方体
  •     glColor3f(0.0f,1.0f,0.0f); // 颜色改为蓝色
  •     glVertex3f( 1.0f, 1.0f,-1.0f); // 四边形的右上顶点 (顶面)
  •     glVertex3f(-1.0f, 1.0f,-1.0f); // 四边形的左上顶点 (顶面)
  •     glVertex3f(-1.0f, 1.0f, 1.0f); // 四边形的左下顶点 (顶面)
  •     glVertex3f( 1.0f, 1.0f, 1.0f); // 四边形的右下顶点 (顶面)
  •     glColor3f(1.0f,0.5f,0.0f); // 颜色改成橙色
  •     glVertex3f( 1.0f,-1.0f, 1.0f); // 四边形的右上顶点(底面)
  •     glVertex3f(-1.0f,-1.0f, 1.0f); // 四边形的左上顶点(底面)
  •     glVertex3f(-1.0f,-1.0f,-1.0f); // 四边形的左下顶点(底面)
  •     glVertex3f( 1.0f,-1.0f,-1.0f); // 四边形的右下顶点(底面)
  •     glColor3f(1.0f,0.0f,0.0f); // 颜色改成红色
  •     glVertex3f( 1.0f, 1.0f, 1.0f); // 四边形的右上顶点(前面)
  •     glVertex3f(-1.0f, 1.0f, 1.0f); // 四边形的左上顶点(前面)
  •     glVertex3f(-1.0f,-1.0f, 1.0f); // 四边形的左下顶点(前面)
  •     glVertex3f( 1.0f,-1.0f, 1.0f); // 四边形的右下顶点(前面)
  •     glColor3f(1.0f,1.0f,0.0f); // 颜色改成黄色
  •     glVertex3f( 1.0f,-1.0f,-1.0f); // 四边形的右上顶点(后面)
  •     glVertex3f(-1.0f,-1.0f,-1.0f); // 四边形的左上顶点(后面)
  •     glVertex3f(-1.0f, 1.0f,-1.0f); // 四边形的左下顶点(后面)
  •     glVertex3f( 1.0f, 1.0f,-1.0f); // 四边形的右下顶点(后面)
  •     glColor3f(0.0f,0.0f,1.0f); // 颜色改成蓝色
  •     glVertex3f(-1.0f, 1.0f, 1.0f); // 四边形的右上顶点(左面)
  •     glVertex3f(-1.0f, 1.0f,-1.0f); // 四边形的左上顶点(左面)
  •     glVertex3f(-1.0f,-1.0f,-1.0f); // 四边形的左下顶点(左面)
  •     glVertex3f(-1.0f,-1.0f, 1.0f); // 四边形的右下顶点(左面)
  •     glColor3f(1.0f,0.0f,1.0f); // 颜色改成紫罗兰色
  •     glVertex3f( 1.0f, 1.0f,-1.0f); // 四边形的右上顶点(右面)
  •     glVertex3f( 1.0f, 1.0f, 1.0f); // 四边形的左上顶点(右面)
  •     glVertex3f( 1.0f,-1.0f, 1.0f); // 四边形的左下顶点(右面)
  •     glVertex3f( 1.0f,-1.0f,-1.0f); // 四边形的右下顶点(右面)
  •     glEnd(); // 立方体绘制结束
  •     rtri+=0.5f; // 增加三角形的旋转变量(新增)
  •     rquad-=0.55f; // 减少四边形的旋转变量(新增)
  •     return TRUE; // 继续运行
  • };