Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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;.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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