29

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?

2 Answers 2

16

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.

2
  • 12
    you didn't specify what "out vec4 color" means, you instead talking about something else called "diffuseColor" which i don't know what it is either Commented Aug 11, 2019 at 4:11
  • 1
    diffuseColor is literally just a variable name. All OpenGL cares about is that there be a vec4 at output layout location 0
    – Moosa
    Commented Nov 12, 2022 at 11:56
8

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.