Lets say I have this GLSL code:

#version 330

out vec4 outputColor;

void main()
    float lerpValue = gl_FragCoord.y / 500.0f;

    outputColor = mix(vec4(1.0f, 1.0f, 1.0f, 1.0f),
        vec4(0.2f, 0.2f, 0.2f, 1.0f), lerpValue);

(taken from http://www.arcsynthesis.org/gltut/Basics/Tutorial%2002.html)

How does OpenGL determine that outputColor is in fact what color the fragment should be?


By default the output variable (outputColor) is bound to location 0. For a fragment shader this specifies the color value to be used for that fragment for the framebuffer object in position 0.

You can bind the output variable to different locations in the application code using glBindFragDataLocation() or in the shader like this layout(location = 0) out vec4 colorOut;.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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