繁体   English   中英

glGenBuffers 2个名字?

[英]glGenBuffers 2 names?

我一直在实现一个基于本教程的小型opengl应用程序: http : //openglbook.com/the-book/chapter-4-entering-the-third-dimension/

我了解大多数代码,但对这一行感到非常困惑:

glGenBuffers(2, &BufferIds[1]); 

然后是

glBindBuffer(GL_ARRAY_BUFFER, BufferIds[1]);
glBufferData(GL_ARRAY_BUFFER, size,  &theModel->theMesh.pos[0], GL_STATIC_DRAW);

我假设我只需要一个免费的名称/ ID即可将我的缓冲区数据绑定到其中,但是如果我更改

 glGenBuffers(2,

 glGenBuffers(1,

缓冲区无法绑定,没有任何作用。

BufferIds的大小为3(GLuint BufferIds [3])。 我想使用第一个插槽作为VAO,第二个插槽作为VBO,使其成为BufferIds [2]。

glGenVertexArrays(1, &BufferIds[0]); 
ExitOnGLError("ERROR: Could not generate the VAO"); 
glBindVertexArray(BufferIds[0]); 
ExitOnGLError("ERROR: Could not bind the VAO"); 

glEnableVertexAttribArray(0); 
glEnableVertexAttribArray(1); 
glEnableVertexAttribArray(2); 

ExitOnGLError("ERROR: Could not enable vertex attributes"); 

glGenBuffers(2, &BufferIds[1]);  //if this gets from changed 2 to 1 ...
ExitOnGLError("ERROR: Could not generate the buffer objects"); 

int size = theModel->theMesh.pos.size() * sizeof(theModel->theMesh.pos[0]) ; 

glBindBuffer(GL_ARRAY_BUFFER, BufferIds[1]); 
ExitOnGLError("ERROR: Could not bind the VBO to the VAO");  // ...this error triggers
glBufferData(GL_ARRAY_BUFFER, size, &theModel->theMesh.pos[0], GL_STATIC_DRAW);

那是因为您将BufferIds [1]传递给glBindBuffer。 索引1实际上是第二个元素,因此,当您仅创建一个缓冲区时,代码将崩溃。

试试看:

glGenBuffers(1, &BufferIds[0]);
glBindBuffer(GL_ARRAY_BUFFER, BufferIds[0]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM