Using gl_FragColor vs. out vec4 color?

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.


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.