About gl_FragColor of fragment shader

Hi dear all,
I’m trying the following fragment shader

#version 460 core

out vec4 whatever;

void main()
{
    whatever = vec4(1,0,0,1);
};

in the shader , I’m writing to whatever instead of gl_FragColor and the rendering result is the same , how does this happen ? many thanks!

GLSL 1.3 added user-defined fragment shader outputs and deprecated the gl_FragColor and gl_FragData variables.

You can use glBindFragDataLocation or a layout(location=...) qualifier to associate a fragment shader output variable with a specific output location.

#version 460 core

layout(location=0) out vec4 whatever;

void main()
{
    whatever = vec4(1,0,0,1);
};

also works. so does that mean location 0 is reserved for the color output ? Is there any sentences in the GL specification that describe this topic ? many thanks!

It means that the value of whatever is copied to output location zero. For the initial state and the default framebuffer, that will be the front buffer for single buffered contexts and the back buffer for double-buffered contexts. For a FBO, it will be whatever is bound to colour attachment zero. The relationship between output locations and buffers or attachments is controlled by glDrawBuffers.

In the 4.6 specification, this is covered in chapter 9 and section 17.4.