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"
-
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 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"
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" -
Actually, compiler may be pointing on your mistake. You haven't set version of GLSL in your shaders.
-
@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...
:-( -
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. -
@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)? -
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. -
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. -