Problem with ShaderProgram



  • I am following an opengl tutorial that uses qt. I have made a GLWidget class that derives from QGLWidget. My class has a QGLShaderProgram member to compile and link the shader programs. The tutorial has a very simple vertext shader

    @
    uniform mat4 mvpMatrix;

    in vec4 vertex;

    void main()
    {
    gl_Position = mvpMatrix * vertex;
    }
    @

    and a fragment shader

    @
    uniform vec4 color;

    out vec4 fragColor;

    void main(void)
    {
    fragColor = color;
    }
    @

    When I use the QGLShaderProgram to add and link them I get the following errors
    @
    QGLShader::compile(Vertex): 0:6(15): error: in' qualifier in declaration ofvertex' only valid for function parameters in GLSL 1.10.
    QGLShader::compile(Fragment): 0:6(19): error: out' qualifier in declaration offragColor' only valid for function parameters in GLSL 1.10.
    @

    I ran

    @
    qDebug() << "OpenGL Versions Supported: " << QGLFormat::openGLVersionFlags();
    qDebug() << QLatin1String(reinterpret_cast<const char*>(glGetString(GL_VERSION)));
    @

    and got the output
    @
    OpenGL Versions Supported: QFlags(0x1|0x2|0x4|0x8|0x10|0x20|0x40|0x1000)
    "3.0 Mesa 9.1.4"
    @

    Shouldn't it be using glsl 1.3?
    I am not sure why I am getting this error.

    here is the code I use to add them

    @
    void GLWidget::initializeGL()
    {
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    qglClearColor(QColor(Qt::black));
    
    shaderProgram.addShaderFromSourceFile&#40;QGLShader::Vertex, "../test/shaders/vertexShader.vsh"&#41;;
    shaderProgram.addShaderFromSourceFile&#40;QGLShader::Fragment, "../test/shaders/fragmentShader.fsh"&#41;;
    shaderProgram.link();
    
    qDebug() << "OpenGL Versions Supported: " << QGLFormat::openGLVersionFlags();
    qDebug() << QLatin1String(reinterpret_cast<const char*>(glGetString(GL_VERSION)));
    
    verticies << QVector3D(1,0,-2) << QVector3D(0,1,-2) << QVector3D(-1,0,-2);
    

    }
    @



  • Try running the program without in and out qualifiers in the shaders



  • I did some more research and changed the shaders

    Fragment Shader
    @
    uniform vec4 color;

    void main(void)
    {
    gl_FragColor = color;
    }
    @

    Vertex Shader
    @
    uniform mat4 mvpMatrix;

    attribute vec4 vertex;

    void main()
    {
    gl_Position = mvpMatrix * vertex;
    }
    @

    It works now.


Log in to reply
 

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