Can't access OpenGL Attribute or Uniform values

  • Hi there,

    First of all I'm using Qt 4.8 and have been quite happy with the OpenGL bindings for it. Now that I've started using Shaders I bumped into some trouble though. My first test was overriding all colours with a default, which worked fine. My second test exists of passing in this color value from outside. The problem is though, Qt can't find the variable for me. Here's what I've got so far:

    Initializing my shader program

    @ std::string sourceCode = "attribute mediump vec4 color;\n"
    "void main(void){"
    "gl_FragColor = color;"

    QGLShader* shader = new QGLShader(QGLShader::Fragment);

    QGLShaderProgram* program = new QGLShaderProgram(m_glContext);

    Changing values for different objects i want to draw

    QColor color2(0, 255, 0, 255);
    int colorLocation = m_program->attributeLocation("color");
    if (colorLocation == -1) {
    std::cerr << "Attribute location not found" << std::endl;
    m_program->setAttributeValue(colorLocation, color2);

    This outputs "Attribute location not found" and nets me black objects on the screen.

    Don't worry about names not matching, it's probably stored in some variable. Before you point out a name mismatch or anything, keep in mind I've got this working for 'color' fixed, instead of as an attribute variable.

    Could someone please point me in the right direction? I'm using the simple tutorial from "the official docs": but alas, nothing.

  • That's an invalid fragment shader to begin with. Attributes are only used in vertex shaders. What you want is either a varying or a uniform.

Log in to reply