when I switch to use OpenGL ES 3 with GLSL 300, I met the following error in my frag shader
undeclared identifier gl_FragColor
when using GLSL 100, everything is fine.
It is based on OpenGL ES 2.0, and according to the spec, it must support GLSL ES version 1.00. In fact that is all it supports. Another good reference for WebGL is the official Khronos WebGL Cheat Sheet.
Shaders use GLSL (OpenGL Shading Language), a special OpenGL Shading Language with syntax similar to C. GLSL is executed directly by the graphics pipeline. There are several kinds of shaders, but two are commonly used to create graphics on the web: Vertex Shaders and Fragment (Pixel) Shaders.
To initialize an array you can use a constructor. Like in object orientation GLSL has a constructor for arrays. The syntax is as follows. int a[4] = int[](4, 2, 0, 5, 1); float a[5] = float[5](3.4, 4.2, 5.0, 5.2, 1.1); int[] c = int[3](1, 2, 3); int[] d = int[](5, 7, 3, 4, 5, 6);
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.
Modern versions of GLSL do fragment shader outputs simply by declaring them as out
values, and gl_FragColor
is no longer supported, hence your error. Try this:
out vec4 fragColor;
void main()
{
fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
Note that gl_FragDepth
hasn't changed and is still available.
For more information see https://www.opengl.org/wiki/Fragment_Shader
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With