[SOLVED]OpenGL as underlay with qml



  • Hello forum,

    I am using the OpenGL Mathematics Library to do the affine transformation instead of the ones that come along with Qt. My intention is to use Qt only for the UI and the OpenGL context creation in platform independent manner. When i run the debugger I cannot access some of the information as follows:

    std::vector<glm::vec3> mVertices;
    
    

    The above is the declaration made inside the class header file and inside the source file, I am initializing the vector as follows:

    mVertices.resize(64);
    

    And the program crashes at the following command :

    glDrawArrays(GL_LINE_STRIP,0,mShowPoints);
    

    More details are pasted here:

    void Hilbert2DScene::render()
    {
        /*
         * Bind the vertex array object and vertex buffer object
         * */
        glBindVertexArray(mVaoID);
        /*
         * Now bind it to the context using the GL_ARRAY_BUFFER binding point
         * */
        glBindBuffer(GL_ARRAY_BUFFER,mVboVerticesID);
    
        mShader->Use();
    
        GL_CHECK_ERRORS;
    
        //allocate the buffer if the buffer is not allocated yet
        if(!mIsBufferAllocated)
        {
            //ALLOCATE THE BUFFER HERE
            unityCube(mIteration,mDim);
    
            //specify the amount of storage we want to use for the buffer
            glBufferData(GL_ARRAY_BUFFER,sizeof(glm::vec3) * mVertices.size(),&mVertices[0],GL_STATIC_DRAW);
    
            mIsBufferAllocated = true;
    
            mShowPoints = getNumberOfPointsForIteration(mIteration,mDim);
        }
    
        if(mClearBackground)
            glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
    
        static const GLfloat color[] = {0.0f,0.0f,0.0f,1.0f};
        static const GLfloat depth = 1.0f;
    
        glClearBufferfv(GL_COLOR,0,color);
        glClearBufferfv(GL_DEPTH,0,&depth);
    
    
        //draw stuff
    
        //transfer the scene along the z-axis
        glm::mat4 T = glm::translate(glm::mat4(1.0f),glm::vec3(0.0f,0.0f,mDist));
    
        //the rotation matrix along X concatenated with the translation matrix
        glm::mat4 Rx = glm::rotate(T, glm::radians(static_cast<float>(mRX)),glm::vec3(1.0f,0.0f,0.0f));
    
        //rotation matrix along Y is concatenated with the rotation matrix along X
        glm::mat4 MV = glm::rotate(Rx,glm::radians(static_cast<float>(mRY)),glm::vec3(0.0f,1.0f,0.0f));
    
        mModelViewMatrix = mProjectionMatrix * MV;
    
        glEnableVertexAttribArray((GLuint)0);
    
    
        glUniformMatrix4fv(mShader->getUniform("MVP"),1,GL_FALSE,glm::value_ptr(mModelViewMatrix));
    
        if(mShowPoints < getNumberOfPointsForIteration(mIteration,mDim))
            ++mShowPoints;
    
        glDrawArrays(GL_LINE_STRIP,0,mShowPoints);
    
    
        glDisableVertexAttribArray(0);
        glBindVertexArray(0);
    
        GL_CHECK_ERRORS;
    
        mShader->UnUse();
    }
    

    Looking forward to some hint to debug this issue.

    Thanks



  • Sorry folks, I believe that I have not explained enough. I cannot access the size of the vector while debugging. If I could access the size , I could have assumed the reason behind the crash.

    Thanks


  • Qt Champions 2016

    Hi, what you mean not access ?
    I can see a std::vector and even expand it to see all elements.

    However, I had to do the following
    Tools -> Options -> Debugger -> GDB tab
    Uncheck the option (Load system GDB pretty printers)

    For it to work.

    No idea if its related to what you ask but better to ask than to assume its not :)



  • @mrjj

    Thanks for the hint , it did solve part of the issue, I do can see the value of the 3rd party library members (glm) and am still working on what may have causing the crash without any hint. I have tried with gdb backtrace command , but it shows only ?? and as mentioned before the application crashes at

    glDrawArrays(GL_LINE_STRIP,0,mShowPoints);
    

    Any further hint over this ?

    Thanks


  • Qt Champions 2016

    @sajis997 said:
    have you output value of mShowPoints ?
    Any chance it get bigger than the list ?

    also did you check that
    sizeof(glm::vec3) * mVertices.size()
    yields the expected size?



  • Hi

    I am sorry. I would like to ask, did you manage all the element values of std::vectorglm::vec3 mVertices ? I still cannot , even after I made the necessary changes as you suggested. It shows "not accessible".

    Thanks


  • Qt Champions 2016

    @sajis997
    Hi well I did not try with that type (glm::vec3) but
    for my own std::vector with all types I can see inside. even expand the inner struct/class.
    Are you on windows or linux/mac?



  • @mrjj

    I am at Ubuntu Linux with Qt 5.4.1 on it.


  • Qt Champions 2016

    @sajis997
    Strange it was exactly on ubuntu I had that
    problem also and the after the option It did show.

    if you make another list say with <int>, it is still not willing to show it ?



  • @mrjj

    I checked with the vector :

    std::vector<GLushort> mIndices;
    

    And I do see all the values inside the vector for type GLushort , but not for type glm::vec3 type. The latter shows "not accessible".
    In that case I cannot be sure if the vector is getting populated with the value I am looking for which may have caused the crash at the point mentioned in my last post.

    Thanks


  • Qt Champions 2016

    @sajis997 said:

    glm::vec3

    Ok. Maybe the namespace confuses it.
    If you press F2 and see definition and then copy it to you program to say
    vec3Test
    and make a list with that, will it see it then ?
    Also you could try to switch to clang code model and see if that helps. (in options)



  • I checked the value of size of the vector mVertices and the value of the variable mShowPoints and both of them are showing the same value in the debugger. The application still crashes at

    glDrawArrays(GL_LINE_STRIP,0,mShowPoints);
    

    Any more hint to look into ?


Log in to reply
 

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