当前位置:网站首页>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);
将相应的数据汇入。
边栏推荐
- 星盟-pwn-fog
- 微信小程序启动页的实现
- 将一个excel文件中多个sheet页“拆分“成多个“独立“excel文件
- Open Source Machine Learning Database OpenMLDB Contributor Program Fully Launched
- He Kaiming's new work ViTDET: target detection field, subverting the concept of layered backbone
- 解决AttributeError: ‘NoneType‘ object has no attribute ‘val‘ if left.val!=right.val:Line 17 问题
- 【LeetCode-13】罗马数字转整数
- 8-byte standard request parsing during USB enumeration
- JVM学习四:垃圾收集器与内存回收策略
- JS this关键字
猜你喜欢

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

heap2 (tcache attack,house of orange)

Day 79

The official website of OpenMLDB is upgraded, and the mysterious contributor map will take you to advance quickly

Day 82

js learning advanced BOM part (pink teacher notes)

Tinker的自我介绍

【LeetCode-49】字母异位词分组

Real-time Feature Computing Platform Architecture Methodology and Practice Based on OpenMLDB

【LeetCode-34】在排序数组中查找元素的第一个和最后一个位置
随机推荐
Day 75
JVM学习四:垃圾收集器与内存回收策略
8-byte standard request parsing during USB enumeration
无效的修订:3.18.1-g262b901-dirty
The Summer of Open Source 2022 is coming | Welcome to sign up for the OpenMLDB community project~
Asis2016 books null off by one
Byte (byte) and bit (bit)
stack stack
Tinker接入全流程---配置篇
C语言-6月10日-my_strcat函数的编写
C语言-6月10日-my_strcpy函数的编写
【LeetCode-36】有效的数独
The third phase of the contributor task is wonderful
品优购项目实战笔记
Dark Horse Event Project
Scene-driven feature calculation method OpenMLDB, efficient implementation of "calculate first use"
C语言-7月19日-指针的学习
Jetpack use exception problem collection
详解程序执行过程
自己动手写RISC-V的C编译器-00环境配置