• glVertexAttribPointer 用法简介


    在内存中采用交叉模式存储,向gpu传入顶点数据的方法 
    这里写图片描述 
    GPU:

    #version 100
    attribute highp vec2 aPosition;
    attribute highp vec2 aTexcoord;

    CPU: 
    init()

    //将顶点数组元素都存入一个缓存对象中
        static const float position[] = {
            -1.0f, -1.0f,0.0f,1.0f,//2 顶点位置 2 纹理坐标
            1.0f, -1.0f,1.0f,0.0f,
            -1.0f, 1.0f,0.0f,1.0f,
            1.0f, 1.0f,1.0f,1.0f
        };
    
        //-----------基于索引绘制
        static const GLushort plane_indices[] =
        {
            0, 1, 2, 3
        };
        glGenBuffers(1, &_index_buffer);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _index_buffer);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(plane_indices), plane_indices, GL_STATIC_DRAW);
        //--------------
    
        glGenBuffers(1, &_quad_vbo);
        glBindBuffer(GL_ARRAY_BUFFER, _quad_vbo);
        glBufferData(GL_ARRAY_BUFFER, sizeof(position), NULL, GL_STATIC_DRAW);
        glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(position), position);
    
        glGenVertexArrays(1, &_vao);
        glBindVertexArray(_vao);
    
        GLint naPosition = mProgram->getAttribLocation("aPosition");
        glEnableVertexAttribArray(0);
        //注意,这里的offset 是内存中大小的偏移,必须准确计算出内存大小偏移量 sizeof
        glVertexAttribPointer(naPosition, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), (GLvoid*)0);
    
    
        GLint naTexcoord = mProgram->getAttribLocation("aTexcoord");
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(naTexcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const GLvoid*)(2*sizeof(float)));
    
        glBindVertexArray(0);
        glDisableVertexAttribArray(0);
        glDisableVertexAttribArray(1);
    --------------------- 
    作者:皮皮虾图形学 
    来源:CSDN 
    原文:glVertexAttribPointer 用法简介
    版权声明:本文为博主原创文章,转载请附上博文链接!
  • 相关阅读:
    Android 统一配置依赖管理
    Android图片压缩工具MCompressor
    Android Studio 打包自定义apk文件名
    sourceTree的下载与安装
    Mac环境下SVN的配置和使用
    AndroidStudio环境搭建
    设计模式之策略模式
    设计模式之状态模式
    设计模式之观察者模式
    mysql 查询小demo
  • 原文地址:https://www.cnblogs.com/rainbow70626/p/10231138.html
Copyright © 2020-2023  润新知