home/ atoms/ glsl-fragcolor-main-required

Every GLSL fragment shader must define void main() and assign gl_FragColor at least once

A GLSL fragment shader is required to define a void main() entry point and assign gl_FragColor (a vec4) before returning. Forgetting either produces a link error or renders a black/garbage frame. The assignment must be reachable on all code paths — an early return before the assignment leaves gl_FragColor unwritten. The minimum valid shader is: void main() { gl_FragColor = vec4(rgb, 1.0); }.

Examples

void main() {
    gl_FragColor = vec4(0.03, 0.03, 0.05, 1.0);
}

Assessment

State the two required elements of a valid minimal GLSL fragment shader and explain what happens if either is missing.

“No `gl_FragColor` written / no `main`** | forgot to assign the output, or renamed `main` | Link error, or a black/garbage frame”
context/ · L5-debug/glsl.md · chunk 1