Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt3D: Basic Shapes C++ Example doesn't run

    General and Desktop
    qt3d examples
    4
    8
    5364
    Loading More Posts
    • 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.
    • Y
      yoavmil last edited by

      I tried to run the simple Qt3D: Basic Shapes C++ Example, but it doesn't work, doesn't show the shapes.

      windows7 qt5.5 mingw
      this is what I get:

      Starting C:\Qt5.5.0\Examples\Qt-5.5\qt3d\build-basicshapes-cpp-Desktop_Qt_5_5_0_MinGW_32bit-Debug\debug\basicshapes-cpp.exe...
      setGeometryDp: Unable to set geometry 1200x800+360+124 on QWidgetWindow/'QWidgetClassWindow'. Resulting geometry: 1200x750+360+124 (frame: 8, 30, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 427x155, maximum size: 16777215x16777215).
      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"

      P 1 Reply Last reply Reply Quote 0
      • A
        alex_malyu last edited by

        @yoavmil said:

        Qt3D: Basic Shapes C++ Example

        I have not built Qt3D, but this is not the code from

        http://doc.qt.io/qt-5/qt3drenderer-basicshapes-cpp-main-cpp.html

        First of all nothing in QT should be instantiated before before QApplication instance
        and none of your main shows required code.

        Second, even though I have not tried Qt3D, but I assume some initialization is required.
        This probably is done in:

        Qt3D::QAspectEngine engine;
        engine.registerAspect(new Qt3D::QRenderAspect());
        Qt3D::QInputAspect *input = new Qt3D::QInputAspect;
        engine.registerAspect(input);
        engine.initialize();
        

        Unfortunately I can't help more.

        Regards,
        Alex

        1 Reply Last reply Reply Quote 0
        • P
          privet @yoavmil last edited by

          @yoavmil
          yeah, it seems, that you have the same problem, as my issue:
          https://forum.qt.io/topic/56810

          The root cause of the problem seems to be
          https://bugreports.qt.io/browse/QTBUG-46158

          Unfortunately, there is no solution in sight yet ;-(((

          The only "solution": Qt3D seems to work on high-end graphic cards.
          Which graphic card do you have?

          1 Reply Last reply Reply Quote 0
          • Y
            yoavmil last edited by

            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.

            P S 2 Replies Last reply Reply Quote 4
            • P
              privet @yoavmil last edited by

              @yoavmil
              thx!
              most of the examples are working for me now also, after commenting out the
              format.setVersion(4,3);
              line!

              1 Reply Last reply Reply Quote 0
              • S
                steventaitinger @yoavmil last edited by

                @yoavmil Thank you! Can you tell me how you troubleshooted this problem? I need to learn how to troubleshoot not just google solutions :)

                Y 1 Reply Last reply Reply Quote 0
                • Y
                  yoavmil @steventaitinger last edited by

                  @steventaitinger said:

                  hank you! Can you tell me how you troubleshooted this problem? I need to learn how to troubleshoot not just google solutions :)

                  how to troubleshoot? thats a hard question. in this case
                  a. I knew that it was a openGL shader compile error. I saw it on the output.
                  b. I knew Qt3D was supposed to be open source, so I found the source on the net.
                  c. I searched the code to see where the shaders were, and found them at "qt3d-dev\src\render\shaders*"
                  d. saw also there an "es2" directory. GLSL is a little different for mobile devices, I think. therefor they have different shaders.
                  e. look at the Qt3D source code where the actual shaders were loading, searched for "es2" at the code. found it at "rederer.cpp", and saw that the code selects which shaders to use according the function, "isOpenGLES()".
                  f. looked it up, and then some trial and error, and found the source of the problem.

                  Trouble shooting is mostly intuition and experience. Programmers around the world think the same and make the same decisions and the same mistakes.

                  1 Reply Last reply Reply Quote 0
                  • P
                    privet last edited by

                    Hi,

                    most of the Qt3D-demos are now working also for me,
                    just some of them have still errors (=application remains completely black):
                    1) assimp* //
                    2) deferred-renderer*
                    3) multiviewport
                    4) tesselation-models
                    5) and I see no difference with and without referencing "test_scene.dae"
                          with SceneLoader in the project "playgorund-qml".
                          What should I expect to see when I reference "test_scene.dae"?
                          ( this is what I see: http://privet.bplaced.net/temp/playground-qml.png )

                    Do you experience the same behavior?

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post