Qt3D: Basic Shapes C++ Example doesn't run
-
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 highpuniform 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 factorvarying 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" -
@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 -
@yoavmil
yeah, it seems, that you have the same problem, as my issue:
https://forum.qt.io/topic/56810The root cause of the problem seems to be
https://bugreports.qt.io/browse/QTBUG-46158Unfortunately, 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? -
I found the solution:
at Window::Window(), mark out this lineformat.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()
, atif (m_graphicsContext->openGLContext()->isOpenGLES()) {
the
isOpenGLES()
is wrong on my PC. -
@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.
-
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?