I see a lot of different fragment shaders,

#version 130

out vec4 flatColor;

void main(void)
{
    flatColor = vec4(0.0,1.0,0.0,0.5);
}

And they all use a different variable for the "out color" (in this case flatColor). So how does OpenGL know what you're trying to do?

I'm guessing this works because flatColor is the only variable defined as out, but you're allowed to add more out variables aren't you? Or would that just crash?


Actually, as a test, I just ran this:

#version 330

in vec2 TexCoord0;

uniform sampler2D TexSampler;

out vec4 x;
out vec4 y;

void main()
{
    y = texture2D(TexSampler, TexCoord0.xy);
}

It worked fine whether I used x or y.

(answer: the compiler is optimizing out the unused var, so the remaining var is assigned to location 0)


Furthermore, we have a predefined gl_FragColor. What's the difference, and why do people usually insist on using their own variables?

Edit
Report