Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When switching to GLSL 300, met the following error

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.

like image 775
Adam Lee Avatar asked Nov 02 '14 01:11

Adam Lee


People also ask

What version of GLSL does WebGL use?

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.

What is GLSL computer graphics?

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.

How do I create an array in GLSL?

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);

Is gl_FragColor deprecated?

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.


1 Answers

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

like image 57
Richard Viney Avatar answered Sep 20 '22 01:09

Richard Viney