OpenGLSL error while compiling fragment shader using UBOs - opengl

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.

Related

Vulkan GLSL shaders in OpenGL

I'm using a shader transpiler tool called 'glslcc' and it supports transpiling into glsl. However I think the GLSL outputs are Vulkan GLSL since it contains things like the following but I might be wrong.
layout(std140) uniform u_Test
{
vec4 test;
} _34;
Will this shader work in OpenGL? If not is there a way to convert from this format to something else so it can be loaded in OpenGL?
This is a Uniform Block that can of course be used with OpenGL (see also Uniform Buffer Object). There is no Vulkan exclusive declaration in this code. The Layout Qualifier std140 was introduced with OpenGL 3.1. See The OpenGLĀ® Shading Language, Version 4.60.7.

Using gl_FragColor vs. out vec4 color?

There seems to be a lot of ambiguity about gl_FragColor being deprecated. For example, it is missing in the GLSL 4.40 specification, but it is included in the GLSL 4.60 specification.
What is the safest, most compatible, most supported strategy? Using gl_FragColor or defining a shader output like out vec4 color?
Yes, gl_FragColor is deprecated. You should use the following syntax:
layout(location = 0) out vec4 diffuseColor;
It is included in the GLSL 4.60 spec under the section 7.1.7. Compatibility Profile Built-In Language Variables. That means, if you create a core context this variable will not be available.
If you would read the the GLSL 4.40 specification carefully, then you would find gl_FragCoord in chapter "7.1.1 Compatibility Profile Built-In Language Variables", as it is in the GLSL 4.60 specification.
The following fragment output variables are available in a fragment shader when using the compatibility profile:
out vec4 gl_FragColor;
out vec4 gl_FragData[gl_MaxDrawBuffers];
Writing to gl_FragColor specifies the fragment color that will be used by the subsequent fixed functionality pipeline. If subsequent fixed functionality consumes fragment color and an execution of the fragment shader executable does not write a value to gl_FragColor then the fragment color consumed is undefined.
This means you can't use gl_FragColor, in an OpenGL Core profile Context, because it is deprecated, but it would still be available in a compatibility profile.
The modern way of writing to the output buffers from a fragment shader, is to declare user-defined output variables and to use Layout Qualifiers.

'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.

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.