Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Problem with ShaderProgram
Forum Updated to NodeBB v4.3 + New Features

Problem with ShaderProgram

Scheduled Pinned Locked Moved Game Development
3 Posts 2 Posters 6.5k 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.
  • M Offline
    M Offline
    Malhcifer
    wrote on last edited by
    #1

    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 of vertex' only valid for function parameters in GLSL 1.10.
    QGLShader::compile(Fragment): 0:6(19): error: out' qualifier in declaration of fragColor' 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);
    

    }
    @

    1 Reply Last reply
    0
    • J Offline
      J Offline
      john_god
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Malhcifer
        wrote on last edited by
        #3

        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.

        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