When switching to GLSL 300, met the following error

Adam Lee picture Adam Lee · Nov 2, 2014 · Viewed 7.7k times · Source

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.

Answer

Richard Viney picture Richard Viney · Nov 2, 2014

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