Qt5 OpenGL GLSL version error - c++

I'm starting out on using OpenGL with Qt, and with Shaders (I have OpenGL experience, but not with shaders yet)
I'm following this tutorial: http://releases.qt-project.org/learning/developerguides/qtopengltutorial/OpenGLTutorial.pdf (the official Qt5 OpenGL tutorial).
The problem is, that when I try to run my program, I get a black screen and the following error messages:
QGLShader::compile(Vertex): ERROR: 0:1: '' : version '130' is not supported
QGLShader::compile(Fragment): ERROR: 0:1: '' : version '130' is not supported
My program is based on a QGLWidget
With some browsing on the interwebs I found out that I need to use an OpenGL 3.2 context, but that Qt likes to use OpenGL 2.x
My computer:
MacBook pro retina '15, late 2012
Intel HD 4000
NVidia GeForce 650M
So, how can I make this work?
EDIT:
My version is 3.2 (set through QGLFormat), without a specified format it uses 2.0
fragmentShader.frag:
#version 130
uniform vec4 color;
out vec4 fragColor;
void main(void)
{
fragColor = color;
}
vertexShader.vert:
#version 130
uniform mat4 mvpMatrix;
in vec4 vertex;
void main(void)
{
gl_Position = mvpMatrix * vertex;
}
Errors (with format, OpenGL 3.2):
QGLShaderProgram: shader programs are not supported
QGLShaderProgram::uniformLocation( mvpMatrix ): shader program is not linked
The program has unexpectedly finished.
Errors (without format, OpenGL 2.0):
QGLShader::compile(Vertex): ERROR: 0:1: '' : version '130' is not supported
QGLShader::compile(Fragment): ERROR: 0:1: '' : version '130' is not supported

Newer QOpenGLWidget doesn't support any constructor with QGLFormat. Instead, in your main.cpp, specify the default QSurfaceFormat for all QOpenGLWidget and QOpenGLContext as following:
// main.cpp
QSurfaceFormat glFormat;
glFormat.setVersion(3, 3);
glFormat.setProfile(QSurfaceFormat::CoreProfile);
QSurfaceFormat::setDefaultFormat(glFormat);
Now you should be able to use something like #version 330 core in your shader.

You should create an QGLFormat object and pass it to the QGLWidget as a constructor parameter. The QGLFormat object should be created as showed in the code below.
QGLFormat glFormat;
glFormat.setVersion( 3, 2 );
glFormat.setProfile( QGLFormat::CoreProfile );

I've got the same error on my macbook (early 2011), and this answer helps me. Basically you deprecate to version120.

Related

Error when compiling shaders GLSL 3.30

I create context by:
new sf::Window(sf::VideoMode(800, 600), "OpenGL",
sf::Style::Default,
sf::ContextSettings(24, 8, 0, 3, 3, sf::ContextSettings::Core)));
I'm loading extensions by glLoadGen for OpenGL 3.3 Core Profile with one extension EXT_texture_compression_s3tc. When I'm compiling shader:
#version 330 core
layout (location = 0) in vec3 vertPos;
layout (location = 5) uniform mat4 modelMat;
layout (location = 6) uniform mat4 viewMat;
layout (location = 7) uniform mat4 projectionMat;
out vec4 fragColor;
void main()
{
gl_Position = projectionMat * viewMat * modelMat * vec4(vertPos, 1.0);
fragColor = vec4(0.5, 0.5, 0.5, 1.0);
}
``
#version 330 core
in vec4 fragColor;
out vec4 outColor;
void main()
{
outColor = fragColor;
}
I get error string:
ERROR: Shader compilation error at shader: "media/shaders/shader.vs.glsl"
0:7(1): error: uniform explicit location requires GL_ARB_explicit_uniform_location and either GL_ARB_explicit_attrib_location or GLSL 3.30.
0:8(1): error: uniform explicit location requires GL_ARB_explicit_uniform_location and either GL_ARB_explicit_attrib_location or GLSL 3.30.
0:9(1): error: uniform explicit location requires GL_ARB_explicit_uniform_location and either GL_ARB_explicit_attrib_location or GLSL 3.30.
but I have OpenGL 3.3 (so GLSL 3.30).
glxinfo prints:
Extended renderer info (GLX_MESA_query_renderer):
Vendor: X.Org (0x1002)
Device: AMD JUNIPER (DRM 2.43.0, LLVM 3.8.0) (0x68be)
Version: 11.2.0
Accelerated: yes
Video memory: 512MB
Unified memory: no
Preferred profile: core (0x1)
Max core profile version: 3.3
Max compat profile version: 3.0
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.0
OpenGL vendor string: X.Org
OpenGL renderer string: Gallium 0.4 on AMD JUNIPER (DRM 2.43.0, LLVM 3.8.0)
OpenGL core profile version string: 3.3 (Core Profile) Mesa 11.2.0
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
So I should be able use GLSL 3.30.
The ability to specify uniform locations in a shader is not part of OpenGL version 3.3 or GLSL version 3.30. It's only a core feature of GL 4.3 or GLSL 4.30. The ability to specify vertex shader input and fragment shader output locations is 3.30, but uniform locations are not.
Explicit uniform location specification doesn't actually require special hardware; it's purely an interface thing. As such, pre-4.x hardware could implement it. However, if your hardware is limited to GL 3.3, then there's a very good chance that the hardware is so old that it stopped being updated by the IHV with new OpenGL features. So even though it could support it, the feature appeared after the IHV stopped updating the hardware.
While NVIDIA has kept some of their 3.3-only hardware up-to-date on recent, non-hardware features, the same cannot be said for Intel or AMD. So even if you have an NVIDIA 3.x GPU that this works on, it's likely that Intel or AMD's 3.x GPUs won't work.
In your case, "Juniper" refers to the Radeon 67xx line. These are GL 4.x parts. However, you're using the open source driver rather than AMD's actual Linux driver, so you're only able to get 3.3 from it.
It would be better to bump your required OpenGL version to match your shader. However, if you wish to keep it as a 3.30 shader and use it as an extension (since you're using the open source driver instead of AMD's driver), you will need an extension declaration below the #version declaration:
#extension GL_ARB_explicit_uniform_location : require
You could try adding the following line that enables the extension below #version 330 core:
#extension GL_ARB_explicit_uniform_location : require

'out can't be used with non-varying' shader compile error on Nvidia driver, Intel works fine, AMD has another error

I tried to run a simple OpenGL 3 app with the following vertex shader program:-
in vec4 vPosition;
out vec2 otexcoord;
uniform mat4 modelview;
uniform mat4 projection;
void main()
{
gl_Position = projection * modelview * vPosition;
otexcoord.s = vPosition.x;
otexcoord.t = vPosition.y * -1.0;
};
I've run this code on 3 GPUs, from different company, and the results are different.
With Intel's driver, there's no error and it runs perfectly.
With Nvidia's driver, the error is 'out can't be used with non-varying otexcoord'.
With AMD's driver, the error is 'Implicit version number 110 not supported by GL3 forward compatible context'
The AMD's one seems to be the least obvious. In fact I don't have any idea about it.
Below is some query string
Intel: OpenGL 3.2.0 - Build 9.17.10.2932 GLSL 1.50 - Build 9.17.10.2932
Nvidia: OpenGL 3.2.0 GLSL 1.50 NVIDIA via Cg compiler
AMD: OpenGL 3.2.12002 Core Profile Context 9.12.0.0 GLSL 4.20
Intel's and Nvidia's are similar, it's a GLSL 1.50 compiler. The AMD's is GLSL 4.20
Below is the question:-
Between Intel's and Nvidia's compilers, which one is working correctly in this case?
What does the error message from AMD's compiler really mean ? And what do I need to correct the error.
You must always use a #version directive. If you do not, then the compiler will assume you mean GLSL version 1.10. Which means that out is not a valid keyword.

Can't compile simple vertex shader [duplicate]

I have a problem when compiling a simple vertex shader in OpenGL, I get the following error messages:
error(#106) Version number not supported by GL2
error(#279) Invalid layout qualifier 'location'
I assume that I must be using the wrong version of GL2, but I have no idea how to find my version number or where to go for an upgrade (and yes I tried to search for an answer.) Attached is a copy of my shader code just for reference and my openGL information.
#version 330 core
layout(location = 0) in vec3 Position;
void main() {
gl_Position.xyz = Position;
}
Vendor: ATI Technologies Inc.
Renderer: ATI Radeon HD 5700 Series
Version: 3.2.9756 Compatibility Profile Context
#version 330 core
This says that your shader uses GLSL version 3.30.
This:
Version: 3.2.9756 Compatibility Profile Context
Means that your OpenGL version is 3.2. The GLSL version that corresponds with OpenGL 3.2 is 1.50. Which is less than 3.30. Hence the lack of compilation.
Update your drivers; those are extremely old. Your card should be able to support GL 4.2.

OpenGLSL error while compiling fragment shader using UBOs

I am trying to get UBOs working, however I get a compilation error in the fragment shader:
ERROR 0:5:"(": synrax error.
Fragment Shader:
layout(std140) uniform Colors
{
vec3 SCol;
vec3 WCol;
float DCool;
float DWarm;
}colors;
Where am I going wrong?
At the begining of your fragment shader source file (the very first line) put this:
#version 140
This means that you are telling the GLSL compiler that you use the version 1.40 of the shading language (you can, of course, use a higher version - see Wikipedia for details).
Alternatively, if your OpenGL driver (and/or hardware) doesn't support GLSL 1.40 fully (which is part of OpenGL 3.1), but only GLSL 1.30 (OpenGL 3.0), you can try the following:
#version 130
#extension GL_ARB_uniform_buffer_object : require
However, this one will work only if your OpenGL 3.0 driver supports the GL_ARB_uniform_buffer_object extension.
Hope this helps.

OpenGL Shader Version Compile Error

I have a problem when compiling a simple vertex shader in OpenGL, I get the following error messages:
error(#106) Version number not supported by GL2
error(#279) Invalid layout qualifier 'location'
I assume that I must be using the wrong version of GL2, but I have no idea how to find my version number or where to go for an upgrade (and yes I tried to search for an answer.) Attached is a copy of my shader code just for reference and my openGL information.
#version 330 core
layout(location = 0) in vec3 Position;
void main() {
gl_Position.xyz = Position;
}
Vendor: ATI Technologies Inc.
Renderer: ATI Radeon HD 5700 Series
Version: 3.2.9756 Compatibility Profile Context
#version 330 core
This says that your shader uses GLSL version 3.30.
This:
Version: 3.2.9756 Compatibility Profile Context
Means that your OpenGL version is 3.2. The GLSL version that corresponds with OpenGL 3.2 is 1.50. Which is less than 3.30. Hence the lack of compilation.
Update your drivers; those are extremely old. Your card should be able to support GL 4.2.