QOpenGLShaderProgram add QOpenGLShader uniform location -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 -
I found my problem. It was my mistake
-
Hi and welcome to devnet,
What mistake was it ? That may help other users
-
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
-
Don't worry, that kind of things can happen
Happy coding !