我有一个VBO,IBO和VAO设置如下:
void createVBO()
{
// Create the IBO and VBO data
GLuint* iboData = new GLuint[m_zIndexCount];
Vertex* vboData = new Vertex[m_zVertexCount];
int iboPos = 0;
int vboPos = 0;
// Create the VBO and IBO
for(int i = 0; i < m_zFragMap[0x36]; i++)
{
// Copy the data to the IBO
memcpy(&iboData[iboPos], m_zMeshes[i]->m_indices, m_zMeshes[i]->m_polyCount * 3 * sizeof(GLuint));//sizeof(*zoneMeshes[i].indices));
// Advance the position
iboPos += m_zMeshes[i]->m_polyCount * 3;
// Copy the data to the VBO
memcpy(&vboData[vboPos], m_zMeshes[i]->m_vertices, m_zMeshes[i]->m_vertCount * sizeof(Vertex));//sizeof(*zoneMeshes[i].vertices));
// Advance the position
vboPos += m_zMeshes[i]->m_vertCount;
}
glGenBuffers(1, &m_zVBO);
glBindBuffer(GL_ARRAY_BUFFER, m_zVBO);
glBufferData(GL_ARRAY_BUFFER, m_zVertexCount * sizeof(Vertex), vboData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenBuffers(1, &m_zIBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_zIBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_zIndexCount * sizeof(GLuint), iboData, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// Create the VAO
glGenVertexArrays(1, &m_zVAO);
glBindVertexArray(m_zVAO);
glBindBuffer(GL_ARRAY_BUFFER, m_zVBO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(sizeof(float) * 3));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(sizeof(float) * 6));
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(sizeof(float) * 8));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_zIBO);
glBindVertexArray(0);
}
我已经输出了VBO和IBO数据中的数据,并且它具有正确的副本。
我将相机矩阵发送到着色器(我已经用一个简单的三角形进行了测试,它已经工作了)。
这是我的渲染(着色器已设置并正常工作):
// Bind the VAO
glBindVertexArray(zone->m_zVAO);
glDrawElements(GL_TRIANGLES, zone->m_zIndexCount, GL_UNSIGNED_INT, (void*)(0));
看起来复制到IBO或VBO时出现问题。有没有人看到任何与代码有关的东西?