zoukankan      html  css  js  c++  java
  • 学习OpenGL:笔记五

    绘制一个正方体

    正方体其实就是由6个矩形组成的几何体,X,Y,Z轴上各两个矩形。

    先绘制X轴上两个矩形

    - (void)drawXPlanes {
        static GLfloat triangleData[] = {
    // X轴0.5处的平面
          0.5,  -0.5,    0.5f, 1,  0,  0,
          0.5,  -0.5f,  -0.5f, 1,  0,  0,
          0.5,  0.5f,   -0.5f, 1,  0,  0,
          0.5,  0.5,    -0.5f, 1,  0,  0,
          0.5,  0.5f,    0.5f, 1,  0,  0,
          0.5,  -0.5f,   0.5f, 1,  0,  0,
    // X轴-0.5处的平面
          -0.5,  -0.5,    0.5f, 1,  0,  0,
          -0.5,  -0.5f,  -0.5f, 1,  0,  0,
          -0.5,  0.5f,   -0.5f, 1,  0,  0,
          -0.5,  0.5,    -0.5f, 1,  0,  0,
          -0.5,  0.5f,    0.5f, 1,  0,  0,
          -0.5,  -0.5f,   0.5f, 1,  0,  0,
        };
        [self bindAttribs:triangleData];
        glDrawArrays(GL_TRIANGLES, 0, 12);
    }

    效果如下图:
                                                      

    接下来绘制Y轴和Z轴上的两个矩形:

    - (void)drawYPlanes {
        static GLfloat triangleData[] = {
            -0.5,  0.5,  0.5f, 0,  1,  0,
            -0.5f, 0.5, -0.5f, 0,  1,  0,
            0.5f, 0.5,  -0.5f, 0,  1,  0,
            0.5,  0.5,  -0.5f, 0,  1,  0,
            0.5f, 0.5,   0.5f, 0,  1,  0,
            -0.5f, 0.5,  0.5f, 0,  1,  0,
             -0.5, -0.5,   0.5f, 0,  1,  0,
             -0.5f, -0.5, -0.5f, 0,  1,  0,
             0.5f, -0.5,  -0.5f, 0,  1,  0,
             0.5,  -0.5,  -0.5f, 0,  1,  0,
             0.5f, -0.5,   0.5f, 0,  1,  0,
             -0.5f, -0.5,  0.5f, 0,  1,  0,
        };
        [self bindAttribs:triangleData];
        glDrawArrays(GL_TRIANGLES, 0, 12);
    }
    
    - (void)drawZPlanes {
        static GLfloat triangleData[] = {
            -0.5,   0.5f,  0.5,   0,  0,  1,
            -0.5f,  -0.5f,  0.5,  0,  0,  1,
            0.5f,   -0.5f,  0.5,  0,  0,  1,
            0.5,    -0.5f, 0.5,   0,  0,  1,
            0.5f,  0.5f,  0.5,    0,  0,  1,
            -0.5f,   0.5f,  0.5,  0,  0,  1,
            -0.5,   0.5f,  -0.5,   0,  0,  1,
            -0.5f,  -0.5f,  -0.5,  0,  0,  1,
            0.5f,   -0.5f,  -0.5,  0,  0,  1,
            0.5,    -0.5f, -0.5,   0,  0,  1,
            0.5f,  0.5f,  -0.5,    0,  0,  1,
            -0.5f,   0.5f,  -0.5,  0,  0,  1,
        };
        [self bindAttribs:triangleData];
        glDrawArrays(GL_TRIANGLES, 0, 12);
    }

    效果如图:

                                                 

    练习的代码

  • 相关阅读:
    WPF 打开文件 打开路径对话框
    WPF Button添加图片
    Delphi 正则表达式PerlRegEx
    解决Inet控件下载utf8网页乱码的问题
    Delphi程序结构
    VB 936(gb2312)URL编码与解码
    Chr 将一个有序数据转换为一个ANSI字符
    Delphi正则表达式使用方法(TPerlRegEx)
    Delphi类型转换
    Delphi 正则表达式TPerlRegEx 类的属性与方法
  • 原文地址:https://www.cnblogs.com/neverMore-face/p/10143359.html
Copyright © 2011-2022 走看看