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. QOpenGLShaderProgram add QOpenGLShader uniform location -1
Forum Updated to NodeBB v4.3 + New Features

QOpenGLShaderProgram add QOpenGLShader uniform location -1

Scheduled Pinned Locked Moved General and Desktop
openglqt5.4
5 Posts 2 Posters 1.6k Views 2 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.
  • D Offline
    D Offline
    Dimitris
    wrote on last edited by
    #1

    Hi there,

    I'm playing around with the triangle example. What I saw is that if I use the QOpenGLShader classes to create the vertex and fragment shaders (instead of add the source string directly) and then add them to a QOpenGLShaderProgram object, getting the uniform location of the matrix returns -1.

    Here it is the code:

    '''void TriangleWindow::initialize()
    {

      QOpenGLShader *vertexShader = new QOpenGLShader(QOpenGLShader::Vertex);
    if (!vertexShader->compileSourceFile(QDir::currentPath() + "/vertexshader.vert"))
    {
        qDebug() << vertexShader->log();
    }
    QOpenGLShader *fragmentShader = new QOpenGLShader(QOpenGLShader::Fragment);
    if (!fragmentShader->compileSourceFile(QDir::currentPath() + "/fragmentshader.frag"))
    {
        qDebug() << fragmentShader->log();
    }
    
    m_program = new QOpenGLShaderProgram(this);
    if (!m_program->addShader(vertexShader)) qDebug() << "Cannot add vertex shader\n";
    if (!m_program->addShader(fragmentShader)) qDebug() << "Cannot add fragment shader\n";
    if (!m_program->link())
    qDebug() << m_program->log();
    
     m_program->bind();
    
    m_posAttr = m_program->attributeLocation("posAttr");
    if (m_posAttr == -1) qDebug() << "Cannot find position\n";
    m_colAttr = m_program->attributeLocation("colAttr");
    if (m_colAttr == -1) qDebug() << "Cannot find colors\n";
    m_matrixUniform = m_program->uniformLocation("matrix");
    if (m_matrixUniform == -1) qDebug() << "Cannot find matrix\n";'''
    

    Am I doing somthing wrong? The shader files hold exactly the same code as the shader string of the example.

    Cheers,
    Dimitris

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dimitris
      wrote on last edited by
      #2

      I found my problem. It was my mistake

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        What mistake was it ? That may help other users

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dimitris
          wrote on last edited by
          #4

          Hi,

          I feel very bad for saying this. I was reading another shader file were the uniform matrix variable wasn't used. And the compiler gets rid of those variables. It was a very stupid mistake!!

          Cheers

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Don't worry, that kind of things can happen

            Happy coding !

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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