当前位置:网站首页>OpenGL中glGenBuffers glBindBuffer glBufferData的理解
OpenGL中glGenBuffers glBindBuffer glBufferData的理解
2022-08-11 05:30:00 【偷不偷月】
glGenBuffers glBindBuffer glBufferData的理解
//顶点数组对象
GLuint VAO1;//即相当于unsigned int
glGenVertexArrays(1, &VAO1);
glBindVertexArray(VAO1);
//顶点缓冲对象
GLuint VBO1;
glGenBuffers(1, &VBO1);
glBindBuffer(GL_ARRAY_BUFFER, VBO1);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
//索引缓冲对象
GLuint EBO;
glGenBuffers(1, &EBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
//以下两行是将VBO与着色器的Attribute进行绑定
// //参数layout,GPU激活0号单元
glEnableVertexAttribArray(0);
//将数据传入着色器中。参数:layout(位置值为0的顶点属性);几维坐标;是否归一化;步长;偏移量
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(sizeof(float)*3));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(sizeof(float) * 6));
参考:链接
参考:链接
个人理解:
第一步:GLuint VBO1;
声明一个GLuint 类型引用变量,不予赋值,待用;
第二步:glGenBuffers(1, &VBO1);
指定缓存空间数量,创建缓存空间,并把空间地址存到变量VBO1下,使用时直接调用地址;
第三步:glBindBuffer(GL_ARRAY_BUFFER, VBO1);
确定该变量存储的缓冲类型,此处为顶点缓冲对象;
第四步:glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
将相应的数据汇入。
边栏推荐
猜你喜欢
js学习进阶BOM部分(pink老师笔记)
本地服务配置内网穿透实现微信公众号整合
开发公众号授权遇到的redirect_uri参数错误
Day 83
Jetpack's dataBinding
Asis2016 books null off by one
JS advanced web page special effects (pink teacher notes)
星盟-pwn-babyfmt
Manufacturer Push Platform-Huawei Access
swagger错误:WARN i.s.m.p.AbstractSerializableParameter - [getExample,421] - Illegal DefaultValue null
随机推荐
jdbc接口文档参考,jdbc接口方法逻辑探究
手把手导入企业项目(快速完成本地项目配置)
The mount command - mounted read-only, solution
Goldbach's conjecture and the ring of integers
OpenMLDB + Jupyter Notebook: Quickly Build Machine Learning Applications
厂商推送平台-华为接入
Regular expression replacement for batch quick modification code
深度学习Matlab工具箱代码注释
helm安装
函数使用记录
SearchGuard configuration
Day 78
经纬度求距离
Day 82
Some formulas for system performance and concurrency
buuctf hacknote
虚拟机更改IP地址
C-8月1日-递归与动态内存管理
JS advanced web page special effects (pink teacher notes)
The whole process of Tinker access --- Compilation