Hello,
I have the problem, that when I use Vertex Buffer Array in combination with Index Buffer Arrays, nothing appears on the screen. If I'm using only a Vertex Buffer Array, that works fine. I uploaded the project: example_VertexAttrib.zip (works with Qt 4.8 and above)
My Header includes both arrays:
Code :QVector<float> vertices_; QVector<short> indices_;
I'm initializing both arrays in the Constructor:
Code :/* Push back all vertices */ vertices_.reserve(16); vertices_ << -1 << -1 << -1 // a 0 << 1 << -1 << -1 // b 1 << 1 << 1 << -1 // c 2 << -1 << 1 << -1 // d 3 << -1 << -1 << 1 // e 4 << 1 << -1 << 1 // f 5 << 1 << 1 << 1 // g 6 << -1 << 1 << 1; // h 7 /* Push back all indices */ indices_.reserve(16); indices_ << 0 << 1 << 2 << 3 // front << 4 << 5 << 6 << 7 // rear << 1 << 5 << 6 << 2 // right << 4 << 0 << 3 << 7; // left
Buffer Objects are prepared inside QGLWidget::initializeGL()
Code :static const int VERTICES = 0; static const int INDICES = 1; // -- Buffer Objects -- GLuint bufferObjectVertices; GLuint bufferObjectIndices; QGLFunctions::glGenBuffers(1, &bufferObjectVertices); QGLFunctions::glGenBuffers(1, &bufferObjectIndices); QGLFunctions::glBindBuffer(GL_ARRAY_BUFFER, bufferObjectVertices); QGLFunctions::glBufferData(GL_ARRAY_BUFFER, vertices_.size() * sizeof(float), &vertices_.front(), GL_STATIC_DRAW); QGLFunctions::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjectIndices); QGLFunctions::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_.size() * sizeof(short), &indices_.front(), GL_STATIC_DRAW); QGLFunctions::glVertexAttribPointer(VERTICES, 3, GL_FLOAT, false, 0, 0); QGLFunctions::glEnableVertexAttribArray(VERTICES); GLuint programId = shaderProg_.programId(); QGLFunctions::glBindAttribLocation(programId, VERTICES, "Vertex");
And I'm trying to draw them inside QGLWidget:aintGL()
Code :glDrawElements(GL_QUADS, indices_.size(), GL_SHORT, 0);



aintGL()
