我有一个 bunny.h,其中包含以下数据:
bunny[] | vertex coordinates xyz
NUM_TRIANGLES | the amount of triangles for the bunny
normals[] | the normals for each triangle
triangles[] | indices for the triangles
我想将数据用于顶点缓冲区对象。
这是我尝试加载数据的方式
GLfloat values[NUM_TRIANGLES*3];
for(int i = 0; i < NUM_TRIANGLES*3; i++)
values[i] = bunny[i];
// init and bind a VBO (vertex buffer object) //
glGenBuffers(1, &bunnyVBO);
glBindBuffer(GL_ARRAY_BUFFER, bunnyVBO);
// copy data into the VBO //
glBufferData(GL_ARRAY_BUFFER, sizeof(values), &values, GL_STATIC_DRAW);
// init and bind a IBO (index buffer object) //
glGenBuffers(1, &bunnyIBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bunnyIBO);
// copy data into the IBO //
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(triangles), &triangles, GL_STATIC_DRAW);
// unbind active buffers //
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
稍后在程序中,我想使用以下代码呈现缓冲区:
glBindBuffer(GL_ARRAY_BUFFER, bunnyVBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bunnyIBO);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawElements(GL_TRIANGLES, NUM_TRIANGLES, GL_UNSIGNED_INT, triangles);
glDisableClientState(GL_VERTEX_ARRAY);
OpenGL工作正常,但我没有看到兔子......(数据没有损坏或类似的东西,错误在我的代码中)有人可以帮助我吗?