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. Qt3D Demos: "QOpenGLShader::compile(Vertex): ERROR: 2:1: '' : syntax error: #version is mandatory and should be set before any other token" + "QOpenGLShader::link: "ERROR: Definition for \"void main()\" not found.\n"

Qt3D Demos: "QOpenGLShader::compile(Vertex): ERROR: 2:1: '' : syntax error: #version is mandatory and should be set before any other token" + "QOpenGLShader::link: "ERROR: Definition for \"void main()\" not found.\n"

Scheduled Pinned Locked Moved General and Desktop
qt3d
8 Posts 3 Posters 10.1k Views
  • 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.
  • P Offline
    P Offline
    privet
    wrote on 28 Jul 2015, 13:41 last edited by privet
    #1

    The "normal" Qt Demos of Qt 5.5 are working fine when opening + building with QtCreator 3.4.2
    but
    None of the Qt3D Demos are working; they compile fine, but fail during execution with a black screen and the below error output
    ( see also screenshot: http://privet.bplaced.net/temp/qt55_qt3d_examples.png )
    What is wrong?
    How can I fix this?


    Starte C:\Qt\5.5\Src\qt3d\build-examples-5_5_desktop_64bit_vs2013-Release\qt3d\anaglyph-rendering\release\anaglyph-rendering.exe...
    QOpenGLShader::compile(Vertex): ERROR: 2:1: '' : syntax error: #version is mandatory and should be set before any other token

    *** Problematic Vertex shader source code ***
    #define lowp
    #define mediump
    #define highp
    #line 1
    attribute vec3 vertexPosition;
    varying vec3 texCoord0;

    uniform mat4 mvp;
    uniform mat4 inverseProjectionMatrix;
    uniform mat4 inverseModelView;

    void main()
    {
    texCoord0 = vertexPosition.xyz;
    gl_Position = vec4(mvp * vec4(vertexPosition, 1.0)).xyww;
    }


    Failed to compile shader: "ERROR: 2:1: '' : syntax error: #version is mandatory and should be set before any other token\n\n"
    QOpenGLShader::compile(Fragment): ERROR: 2:1: '' : syntax error: #version is mandatory and should be set before any other token

    *** Problematic Fragment shader source code ***
    #define lowp
    #define mediump
    #define highp
    #line 1
    varying highp vec3 texCoord0;
    uniform samplerCube skyboxTexture;

    void main()
    {
    gl_FragColor = textureCube(skyboxTexture, texCoord0);
    }


    Failed to compile shader: "ERROR: 2:1: '' : syntax error: #version is mandatory and should be set before any other token\n\n"
    QOpenGLShader::link: "Link called without any attached shader objects.\n"
    Failed to link shader program: "Link called without any attached shader objects.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::compile(Vertex): ERROR: 2:1: '' : syntax error: #version is mandatory and should be set before any other token

    *** Problematic Vertex shader source code ***
    #define lowp
    #define mediump
    #define highp
    #line 1
    attribute vec3 vertexPosition;
    attribute vec3 vertexNormal;

    varying vec3 position;
    varying vec3 normal;

    uniform mat4 modelView;
    uniform mat3 modelViewNormal;
    uniform mat4 mvp;

    void main()
    {
    normal = normalize( modelViewNormal * vertexNormal );
    position = vec3( modelView * vec4( vertexPosition, 1.0 ) );

    gl_Position = mvp * vec4( vertexPosition, 1.0 );
    

    }


    Failed to compile shader: "ERROR: 2:1: '' : syntax error: #version is mandatory and should be set before any other token\n\n"
    QOpenGLShader::compile(Fragment): ERROR: 2:3: '' : syntax error: #version is mandatory and should be set before any other token

    *** Problematic Fragment shader source code ***
    #define lowp
    #define mediump
    #define highp
    #line 1
    #define FP highp

    uniform FP vec4 lightPosition;
    uniform FP vec3 lightIntensity;

    // TODO: Replace with a struct
    uniform FP vec3 ka; // Ambient reflectivity
    uniform FP vec3 kd; // Diffuse reflectivity
    uniform FP vec3 ks; // Specular reflectivity
    uniform FP float shininess; // Specular shininess factor

    varying FP vec3 position;
    varying FP vec3 normal;

    FP vec3 adsModel( const FP vec3 pos, const FP vec3 n )
    {
    // Calculate the vector from the light to the fragment
    FP vec3 s = normalize( vec3( lightPosition ) - pos );

    // Calculate the vector from the fragment to the eye position
    // (origin since this is in "eye" or "camera" space)
    FP vec3 v = normalize( -pos );
    
    // Reflect the light beam using the normal at this fragment
    FP vec3 r = reflect( -s, n );
    
    // Calculate the diffuse component
    FP float diffuse = max( dot( s, n ), 0.0 );
    
    // Calculate the specular component
    FP float specular = 0.0;
    if ( dot( s, n ) > 0.0 )
        specular = pow( max( dot( r, v ), 0.0 ), shininess );
    
    // Combine the ambient, diffuse and specular contributions
    return lightIntensity * ( ka + kd * diffuse + ks * specular );
    

    }

    void main()
    {
    gl_FragColor = vec4( adsModel( position, normalize( normal ) ), 1.0 );
    }


    Failed to compile shader: "ERROR: 2:3: '' : syntax error: #version is mandatory and should be set before any other token\n\n"
    QOpenGLShader::link: "Link called without any attached shader objects.\n"
    Failed to link shader program: "Link called without any attached shader objects.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"
    QOpenGLShader::link: "ERROR: Definition for "void main()" not found.\n"

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sergey Perevalov
      wrote on 29 Jul 2015, 08:28 last edited by
      #2

      Actually, compiler may be pointing on your mistake. You haven't set version of GLSL in your shaders.

      P 1 Reply Last reply 29 Jul 2015, 11:15
      1
      • S Sergey Perevalov
        29 Jul 2015, 08:28

        Actually, compiler may be pointing on your mistake. You haven't set version of GLSL in your shaders.

        P Offline
        P Offline
        privet
        wrote on 29 Jul 2015, 11:15 last edited by
        #3

        @Sergey-Perevalov
        wow, is the version of GLSL in the shaders not set in the Qt5.5-Qt3D code base?
        (as the errors root cause is in the code of the lib, not in the demo-code)
        Does that mean, that none of the demos is working?
        Does that mean, that nobody has now working Qt5.5-Qt3D code-base?
        That would be a big mistake in the Qt5.5 Release...
        That would mean, that nobody can work with Qt5.5-Qt3D...
        :-(

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sergey Perevalov
          wrote on 29 Jul 2015, 11:34 last edited by
          #4

          Well, I'm working with Qt3D right now and it works just fine.
          Try to add
          #version 150 core
          at the beginning of your shaders.
          By the way, Qt3D module right now is only a technological preview, so some features still not implemented. It is enough for simple renders though.

          P 1 Reply Last reply 29 Jul 2015, 14:24
          1
          • S Sergey Perevalov
            29 Jul 2015, 11:34

            Well, I'm working with Qt3D right now and it works just fine.
            Try to add
            #version 150 core
            at the beginning of your shaders.
            By the way, Qt3D module right now is only a technological preview, so some features still not implemented. It is enough for simple renders though.

            P Offline
            P Offline
            privet
            wrote on 29 Jul 2015, 14:24 last edited by
            #5

            @Sergey-Perevalov
            I was looking at one of the examples
            %Qt%\5.5\Src\qt3d\examples\qt3d\anaglyph-rendering
            and was looking for the problematic code part ... without success!
            See screenshots:
            http://privet.bplaced.net/temp/qt55_qt3d_example_project_all_sources.png
            (showing all sources of the demo on the left, which file do you mean?)
            (in the project, there are no .frag/.vert/.shr files, also no shader in the .qml/.cpp files)
            http://privet.bplaced.net/temp/qt55_qt3d_example_issue_is_not_in_project.png
            (showing when I search for the problematic code from error messages, founding nothing)
            (also nothing found in the examples dir if I search on the file system)
            (error messages: http://privet.bplaced.net/temp/qt55_qt3d_examples.txt)

            Is your app working really on all 'normal' machines, also inside of virtual machines?
            Also with (weak?) Intel graphic cards (Intel HD Graphics 3000)?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sergey Perevalov
              wrote on 30 Jul 2015, 08:54 last edited by
              #6

              These examples work fine on Intel HD Graphics 4400 and on my Android device.
              I looked through the anaglyph rendering example and haven't found any shader references either. That's strange, the problem is obviously in shaders, but I have no clue how to gain access to their source code. Maybe they are located somewhere else in the Qt folder.

              1 Reply Last reply
              1
              • Y Offline
                Y Offline
                yoavmil
                wrote on 1 Aug 2015, 21:30 last edited by
                #7

                I found the solution:
                at Window::Window(), mark out this line

                format.setVersion(4, 3);
                

                for some reason, it makes the Qt3D to think your PC is a ES2 device, making it select the ES2 shaders, which doesn't have the #version whatever line.

                for the Qt developers, look at void Renderer::buildDefaultTechnique() , at if (m_graphicsContext->openGLContext()->isOpenGLES()) {

                the isOpenGLES() is wrong on my PC.

                1 Reply Last reply
                1
                • P Offline
                  P Offline
                  privet
                  wrote on 3 Aug 2015, 09:20 last edited by
                  #8

                  workaround: see
                  https://forum.qt.io/topic/57239/qt3d-basic-shapes-c-example-doesn-t-run/5

                  1 Reply Last reply
                  0

                  6/8

                  30 Jul 2015, 08:54

                  • Login

                  • Login or register to search.
                  6 out of 8
                  • First post
                    6/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved