GlGenVertexArrays has no effect in Qt5.0.2?



  • platform : mac osx 10.8.3
    compiler : clang3.2

    Are these kind of codes do not work on Qt5.0.2?

    @
    GLuint vao;
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);
    @

    example :

    This function has no effect in Qt5, VAO do not record the attributes at all
    It will overwrite the first object in the buffer
    @
    void ch5OverlapNoDepth::paintGL()
    {
    glClear(GL_COLOR_BUFFER_BIT);

    glBindVertexArray(vaoObject1_);
    glDrawElements(GL_TRIANGLES, indexData_.size(), GL_UNSIGNED_INT, 0);
    
    glBindVertexArray(vaoObject2_);
    glDrawElements(GL_TRIANGLES, indexData_.size(), GL_UNSIGNED_INT, 0);
    
    glBindVertexArray(0);
    

    }
    @

    If I want to let QGLWidget draw more than one object
    I have to bind the buffer and enable the attribute in the function
    @
    void ch5OverlapNoDepth::paintGL()
    {
    glClear(GL_COLOR_BUFFER_BIT);

    glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject_[0]);
    
    size_t colorDataOffset = sizeof(GLfloat) * 4 * numberOfVertices;
    int vertexLocation = program_.attributeLocation("position");
    int colorLocation = program_.attributeLocation("color");    
    
    program_.enableAttributeArray(vertexLocation);
    program_.enableAttributeArray(colorLocation);
    
    glVertexAttribPointer(vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, 0);
    glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid const*)colorDataOffset);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, positionBufferObject_[1]);
    glDrawElements(GL_TRIANGLES, indexData_.size(), GL_UNSIGNED_INT, 0);   
    
    size_t posDataOffset = sizeof(float) * 4 * (numberOfVertices / 2);
    colorDataOffset += sizeof(float) * 4 * (numberOfVertices / 2);
    
    //Use the same buffer object previously bound to GL_ARRAY_BUFFER.
    program_.enableAttributeArray(vertexLocation);
    program_.enableAttributeArray(colorLocation);
    glVertexAttribPointer(vertexLocation, 4, GL_FLOAT, GL_FALSE, 0, (void*)posDataOffset);
    glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, 0, (void*)colorDataOffset);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, positionBufferObject_[1]);
    glDrawElements(GL_TRIANGLES, indexData_.size(), GL_UNSIGNED_INT, 0);    
    

    }
    @

    This paintGL looks more expensive than the original paintGL which simply call the associate VAO
    How could I make use of VAO in Qt5.0.2?Thanks



  • I now face with this problem like you. T_T



  • I can fix it.

    You need to make sure your opengl version is 3.0 or newer.
    glGenVertexArray is available in these versions and then use
    create(), bind() , etc instead.



  • Or use the QOpenGL_APPLE_vertex_array_object extension class if using OpenGL 2.1.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.