Using certain OpenGL functions on Linux...



  • Hello,

    The following code block below works on Windows (in VC++ 2013) because I have included GL/glew.h but using QT Creator on Linux it undefines the include so the functions in bold below are not available.

    What can I do to be able to use the OpenGL functions glGetUniformBlockIndex(), glUniformBlockBinding(), and glBindBufferBase() under Linux like how I use these functions under Windows?

    Thank you for your time.
    @
    void QTOpenGLWindow::loadShaderUniforms() {

    glUseProgram(MainOpenGLShaderProgramID);

    MatricesUniformBlockID = glGetUniformBlockIndex(MainOpenGLShaderProgramID, "Matrices");
    glUniformBlockBinding(MainOpenGLShaderProgramID, MatricesUniformBlockID, 1);
    glGenBuffers(1, &MatricesUniformBufferID);
    glBindBuffer(GL_UNIFORM_BUFFER, MatricesUniformBufferID);
    glBindBufferBase(GL_UNIFORM_BUFFER, 1, MatricesUniformBufferID);
    GLsizeiptr TotalBufferSize = sizeof(glm::mat4) + sizeof(glm::mat4);
    TotalBufferSize += sizeof(glm::mat3);

    glBufferData(GL_UNIFORM_BUFFER, TotalBufferSize, NULL, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_UNIFORM_BUFFER, NULL);

    LightsUniformBlockID = glGetUniformBlockIndex(MainOpenGLShaderProgramID, "Lights");
    glUniformBlockBinding(MainOpenGLShaderProgramID, LightsUniformBlockID, 2);
    glGenBuffers(1, &LightsUniformBufferID);
    glBindBuffer(GL_UNIFORM_BUFFER, LightsUniformBufferID);
    glBindBufferBase(GL_UNIFORM_BUFFER, 2, LightsUniformBufferID);

    GLfloat LightDirection[3] = { -4.0f, -3.0f, -3.0f };

    glBufferData(GL_UNIFORM_BUFFER, sizeof(LightDirection), &LightDirection, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_UNIFORM_BUFFER, NULL);

    MaterialsUniformBlockID = glGetUniformBlockIndex(MainOpenGLShaderProgramID, "Materials");
    glUniformBlockBinding(MainOpenGLShaderProgramID, MaterialsUniformBlockID, 3);
    glGenBuffers(1, &MaterialsUniformBufferID);
    glBindBuffer(GL_UNIFORM_BUFFER, MaterialsUniformBufferID);
    glBindBufferBase(GL_UNIFORM_BUFFER, 3, MaterialsUniformBufferID);

    GLfloat Material[18];

    //Diffuse
    Material[0] = 0.5f;
    Material[1] = 0.0f;
    Material[2] = 0.0f;
    Material[3] = 1.0f;

    //Ambient
    Material[4] = 0.2f;
    Material[5] = 0.2f;
    Material[6] = 0.2f;
    Material[7] = 1.0f;

    //Specular
    Material[8] = 1.0f;
    Material[9] = 1.0f;
    Material[10] = 1.0f;
    Material[11] = 1.0f;

    //Emissive
    Material[12] = 0.0f;
    Material[13] = 0.0f;
    Material[14] = 0.0f;
    Material[15] = 1.0f;

    //Shininess
    Material[16] = 5.0f;

    //Texture Count
    Material[17] = 0.0f;

    glBufferData(GL_UNIFORM_BUFFER, sizeof(Material), &Material, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_UNIFORM_BUFFER, NULL);

    }@


  • Moderators

    Combining glew with Qt is a wasted effort as it duplicates functionality. The way to work with OpenGL in Qt is to make your GL class inherit e.g. QOpenGLFunctions_3_3_Core (or whichever version and profile you want to target), call initializeOpenGLFunctions() in the GL initialization function and then all the above GL calls become available in the class scope.


Log in to reply
 

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