From the picture back to the source
OpenGL code mirror
Every control on this page corresponds to exactly one line of fixed-function OpenGL. Change a control and its line lights up on the right; click a line and its control pulses. This is the direction you usually need — you know the look you want, and the question is what to type.
Result
Drag to move the light
The sphere is shaded with the exact equation the code on the right sets up, including attenuation and the emission term.
Your setup function
Light type
—
Shininess
—
Normal length
—
GL_NORMALIZE
—
Light
GL_AMBIENT
—
—
GL_DIFFUSE
—
—
GL_SPECULAR
—
—
GL_POSITION
Material
GL_AMBIENT
—
—
GL_DIFFUSE
—
—
GL_SPECULAR
—
—
GL_EMISSION
—
—
Geometry & normals
Scaling the model scales its normals too. A normal of length other than one breaks the N·L term, so the object goes too dark or blows out. GL_NORMALIZE tells OpenGL to rescale every normal to unit length before lighting it.
Attenuation
Reading the code back
Notice what is not in this listing: nothing computes a colour. You hand OpenGL a light, a material and a normal per vertex, and the fixed-function pipeline evaluates the lighting equation itself, at the vertices, and interpolates between them. That division of labour is precisely what the programmable pipeline hands back to you — a fragment shader replaces this whole listing with arithmetic you write, which is why effects like cel shading become possible.