当前位置:网站首页>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);
将相应的数据汇入。
边栏推荐
- C语言实现扫雷游戏
- 厂商推送平台-华为接入
- The whole process of Tinker access --- configuration
- 微信小程序_开发工具的安装
- 第一章 Verilog语言和Vivado初步使用
- OpenMLDB: Consistent production-level feature computing platform online and offline
- Node stepping on the pit 80 port is occupied
- 本地服务配置内网穿透实现微信公众号整合
- [Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development
- three.js基础学习
猜你喜欢
Event Preview | On April 23, a number of wonderful sharing sessions of OpenMLDB will come, which will live up to the good time of the weekend
【LeetCode-278】第一个错误的版本
8-byte standard request parsing during USB enumeration
Tinker接入全流程---编译篇
【LeetCode-202】快乐数
一文看懂注解与反射
自己动手写RISC-V的C编译器-01实现加减法
js learning advanced BOM part (pink teacher notes)
基于微信小程序云开发实现的电商项目,可以自行定制开发
The whole process of Tinker access --- Compilation
随机推荐
【LeetCode-278】第一个错误的版本
虚拟机更改IP地址
轻松理解进程与线程
JS case exercise (classic case of teacher pink)
Day 87
Node stepping on the pit 80 port is occupied
c语言-数据存储部分
Js method commonly used objects and attributes
Day 86
Here is a memorial
Intelligent risk control China design and fall to the ground
开发公众号授权遇到的redirect_uri参数错误
Use the adb command to manage applications
Jetpack使用异常问题集锦
IIC and SPI
js learning advanced BOM part (pink teacher notes)
js 学习进阶(Dom部分 pink老师教学笔记)
父子节点数据格式不一致的树状列表实现
本地缓存cookie的使用
星盟-pwn-fog