如何解决openGL GLSL 理解顶点数组对象
我正在尝试理解 sierpinski gasket
的代码。这是一些粗略的代码:
标题和常量
#include "Angel.h"
const int NumPoints = 5000;
init()
void init(void)
{
vec2 points[NumPoints];
// Specifiy the vertices for a triangle
vec2 vertices[3] = {
vec2(-1.0,-1.0),vec2(0.0,1.0),vec2(1.0,-1.0)
};
// Select an arbitrary initial point inside of the triangle
points[0] = vec2(0.25,0.50);
// compute and store N-1 new points
for (int i = 1; i < NumPoints; ++i) {
int j = rand() % 3; // pick a vertex at random
// Compute the point halfway between the selected vertex
// and the prevIoUs point
points[i] = (points[i - 1] + vertices[j]) / 2.0;
// CITS3003 Lab1 q1circle: Added the following two lines (and nothing
// else)
if (length(points[i]) > 1.0)
i--;
// Create a vertex array object
gluint vao;
glGenVertexArrays(1,&vao);
glBindVertexArray(vao);
// Create and initialize a buffer object
gluint buffer;
glGenBuffers(1,&buffer);
glBindBuffer(GL_ARRAY_BUFFER,buffer);
glBufferData(GL_ARRAY_BUFFER,sizeof(points),points,GL_STATIC_DRAW);
// Load shaders and use the resulting shader program
gluint program = InitShader("vshader.glsl","fshader.glsl");
gluseProgram(program);
// Initialize the vertex position attribute from the vertex shader
gluint loc = glGetAttribLocation(program,"vPosition");
glEnabLevertexAttribArray(loc);
glVertexAttribPointer(loc,2,GL_FLOAT,GL_FALSE,BUFFER_OFFSET(0));
glClearColor(1.0,1.0,1.0); // white background
}
我理解代码的前半部分。我们正在创建一个向量数组来存储大小为 5000 的大小为 2 (x,y) 的向量。然后我们正在创建一个顶点数组来存储第一个三角形,即它在屏幕空间 (-1,1) 范围内的 3 个顶点。随机,我们选择一个顶点和当前点并找到它的中点并使用下一个当前点进行下一个循环,依此类推。
令人困惑的部分是下一点。我们正在创建一个顶点数组对象。我不太明白这是什么意思,首先我不知道发生了什么,其次为什么在我们不给它任何东西时甚至使用 vao
。
与缓冲区类似。
谁能简要介绍一下正在发生的事情?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。