Quote Originally Posted by wysota View Post
Make sure you are setting up the buffers correctly. I would also advise to use Qt classes for VBO manipulation.
Thanks for your guidance. I solved the problem. The correct code for what I aimed for is:
Qt Code:
  1. if(!initialized)
  2. {
  3. GLuint vertexId = shaderProgram->attributeLocation("vertex");
  4. GLuint colorId = shaderProgram->attributeLocation("color");
  5.  
  6. glGenBuffers(2, VBO_ID);
  7.  
  8. glGenVertexArrays(1, &VAO_ID);
  9. glBindVertexArray(VAO_ID);
  10.  
  11. glBindBuffer(GL_ARRAY_BUFFER, VBO_ID[0]);
  12. glBufferData(GL_ARRAY_BUFFER, sizeof(QVector3D)*verticesSize, vertices.constData(), GL_STATIC_DRAW);
  13. glVertexAttribPointer(vertexId, 3, GL_FLOAT, GL_FALSE, 0, 0);// param - 1 ->0
  14. glEnableVertexAttribArray(vertexId);
  15.  
  16. glBindBuffer(GL_ARRAY_BUFFER, VBO_ID[1]);
  17. glBufferData(GL_ARRAY_BUFFER, sizeof(float)*verticesSize, colors, GL_STATIC_DRAW);
  18. glVertexAttribPointer(colorId, 1, GL_FLOAT, GL_FALSE, 0, 0);
  19. glEnableVertexAttribArray(colorId);
  20.  
  21. glBindBuffer(GL_ARRAY_BUFFER, 0);
  22.  
  23. vertices.clear();
  24.  
  25. free(colors);
  26.  
  27. initialized = true;
  28. }
  29.  
  30. glBindVertexArray(VAO_ID);
  31.  
  32. int vertexLocation = shaderProgram->attributeLocation("vertex");
  33. int colorLocation = shaderProgram->attributeLocation("color");
  34.  
  35. shaderProgram->enableAttributeArray(vertexLocation);
  36. shaderProgram->enableAttributeArray(colorLocation);
  37.  
  38. glEnableClientState(GL_VERTEX_ARRAY);
  39.  
  40. glEnable (GL_BLEND);
  41. glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  42. glDrawArrays(GL_TRIANGLES, 0, 6*numVerts);
  43.  
  44. glFlush();
  45.  
  46. glBindVertexArray(0);
  47.  
  48. glDisableVertexAttribArray(0);
  49. glDisableVertexAttribArray(1);
To copy to clipboard, switch view to plain text mode