我尝试将我的顶点数据转换为 VBO,但总是出现黑屏……我无法弄清楚我的实现有什么问题。在我的渲染中,如果我删除 bindBuffer 调用并将我的顶点指针传递给 glVertexPointer 而不是 0 它可以工作,因此 nbVertices 和顶点被正确填充。
Vec3定义:
struct vec3
{
float x;
float y;
float z;
}
创作:
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vec3) * this->nbVertices, vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER,0);
渲染:
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// draw cube
glScalef(scaleX, scaleY, scaleZ);
glRotatef(rotX, 1, 0, 0);
glRotatef(rotY, 0, 1, 0);
glRotatef(rotZ, 0, 0, 1);
for (int i=0; i<nbTextures; i++)
{
glBindTexture(GL_TEXTURE_2D, textureIds[i]);
glBindBuffer(GL_ARRAY_BUFFER,vertexBuffer);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, 0/*this->vertices*/);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, this->normals);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, this->texCoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, this->nbVertices);
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER,0);