Multiple Vertex Array Objects
-
Hi,
I am quite new in using QT and QTOpenGL. I want to render multiple objects with Vertex Array Objects. I create multiple VAO objects but it always renders the first one, and I see the other ones as only one dot.
Vertex array objects are created in an update function as:
std::shared_ptr<QOpenGLVertexArrayObject> new_PC_VAO = std::make_shared<QOpenGLVertexArrayObject>(); std::shared_ptr<QOpenGLBuffer> new_PC_VBO = std::make_shared<QOpenGLBuffer>(); new_PC_VAO->create(); new_PC_VAO->bind(); bool created = new_PC_VBO->create(); if(created==false){ std::cout<<"ERROR - Vertex Buffer Object Couldn't created!!!" << std::endl; exit(1); } new_PC_VBO->bind(); new_PC_VBO->setUsagePattern(QOpenGLBuffer::StaticDraw); v_VAO.push_back(new_PC_VAO); v_VBO.push_back(new_PC_VBO); new_PC_VBO->allocate( new_data.constData(), new_data.size() * sizeof(GLfloat)); QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0); f->glEnableVertexAttribArray(0); f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat))); f->glEnableVertexAttribArray(1); f->glBindBuffer(GL_ARRAY_BUFFER, 0); new_PC_VBO->release(); new_PC_VAO->release(); this->v_NumVert.push_back( m_logo.vertexCount() );
Then in the GLWidget::paintGL() function after binding the shaders and setting the uniforms in the shaders:
void GLWidget::paintGL() {
//..................................
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
..........................
for(int i=0; i<this->v_VAO.size(); i++) {
this->v_VAO[i]->bind();
f->glDrawArrays(GL_POINTS, 0, v_NumVert[i]);
v_VAO[i]->release();
f->glBindBuffer(GL_ARRAY_BUFFER,0);
}///.....................................
m_program->release();
context()->swapBuffers(context()->surface());}
I tried the same idea with standard openGL, it works, but I don't understand what is different in QT pipeline.
Any idea for the the solution will be a great help.
Best, -
@sinanmut When I create the 3D objects in the initializeGL function, it is fine paintGL function renders these objects. Later on when I want to add new objects to the scene I don't see these new ones being rendered by painGL function. Is there any flag that I have to add in paintGL fuinction or in initializeGL function?
Thanks,