Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using certain OpenGL functions on Linux...

Using certain OpenGL functions on Linux...

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tmason101
    wrote on last edited by
    #1

    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);

    }@

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved