帮助查找错误。
我认为绑定是错误的。在“显示”中,我使用了 VBO - 一切正常。
但是当我使用 VAO - 我得到黑屏。
void createVAO(GLuint *_vId, GLuint *_cId, GLuint *_tId, GLuint *_vao) {
glGenVertexArrays(1, _vao);
glBindVertexArray(*_vao);
glEnableClientState( GL_VERTEX_ARRAY );
glBindBuffer(GL_ARRAY_BUFFER, *_vId );
glVertexPointer( 3, GL_FLOAT, 0, 0 );
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }
void createVBO(GLuint *_vId, GLuint *_cId, GLuint *_tId) {
glGenBuffers(1, _vId);
glBindBuffer(GL_ARRAY_BUFFER, *_vId);
glBufferData(GL_ARRAY_BUFFER, sizeof(XYZ) * cubeVerticesCount, cubePositions, GL_STATIC_DRAW );
glBindBuffer(GL_ARRAY_BUFFER, 0); }
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -800);
glRotatef(rotate.angle_x, 1, 0, 0);
glRotatef(rotate.angle_y, 0, 1, 0);
glScalef(zoom,zoom,zoom);
// VAO - dont work
glColor3f(1.0f,1.0f,1.0f);
glBindVertexArray(vao);
glDrawElements(GL_POINTS, 0, GL_UNSIGNED_INT, NULL);
glBindVertexArray(0);
// VBO - work
//glEnableClientState( GL_VERTEX_ARRAY );
//glBindBuffer( GL_ARRAY_BUFFER, vId );
//glVertexPointer( 3, GL_FLOAT, 0, 0 );
//glDrawArrays(GL_POINTS, 0, cubeVerticesCount);
//glDisableClientState(GL_VERTEX_ARRAY);
calculateFPS();
glutSwapBuffers(); }
完整的源代码。 http://codepad.org/I87AxDl4
我很抱歉有很多不必要的代码。