This tutorial/quick reference explains the steps to setup lighting in OpenGL-ES 1.1 (may be compatible with OpenGL-ES 2.0).
Lighting requires that you prepare your models for lighting first, i.e. set/update material and provide per face/per vertex normals
1. Enable lighting; optionally, enable per vertex/per face color and smooth
shading.
glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_SMOOTH);
2. Enable up to 8 light sources:
glEnable(GL_LIGHTn) // (e.g: GL_LIGHT0)
3. Configure your light sources:
Common to all light types, set light color for ambient, diffuse and specular
light components. Ambient lets a light illuminate every point in a scene, diffuse lets a light illuminate objects around it and specular adds a ‘shiny’ spot to your models.
glLightfv(GL_LIGHTn, GL_AMBIENT, color4f ); glLightfv(GL_LIGHTn, GL_DIFFUSE, color4f ); glLightfv(GL_LIGHTn, GL_SPECULAR, color4f );
note: color4f is array of floats with rgba, eg: {1,0,0,1} is red.
3a. Directional or positional light
glLightfv(GL_LIGHTn, GL_POSITION, vector4f );
note: vector4f is x,y,z + w component
w=0 to create a directional light (x,y,z is the light direction) like the sun
w=1 to create a positional light like a fireball*.
3b. Spotlight
glLightfv(GL_LIGHTn, GL_POSITION, vector4f ); glLightfv(GL_LIGHTn, GL_SPOT_DIRECTION, vector3f ); glLightf(GL_LIGHTn, GL_SPOT_CUTOFF, angle); // angle is 0 to 180 glLightf(GL_LIGHTn, GL_SPOT_EXPONENT, exp); // exponent is 0 to 128
note: high exponent values make the light stronger at the middle of the
light cone.
4. Attenuation
Attenuation makes the power of a light source fade when the model is further from the light source. May slow down rendering.
glLightf(GL_LIGHTn, attenuation, value)
where attenuation is one of:
GL_CONSTANT_ATTENUATION
GL_LINEAR_ATTENUATION
GL_QUADRATIC_ATTENUATION
(*) that won’t actually draw a fireball :), just the lighting effect caused by something like a fireball.

