Before you can render objects with lighting, you need to setup the material. You do this before drawing each object or group of objects sharing the same material.

Use glMaterialfv to setup the current material

glMaterialfv(GL_FRONT_AND_BACK, channelcolor4f);

In OpenGL, you could specify different materials for the front and back of each triangle. In OpenGL-ES 1.1, you have to use the same for both.

channel can take one of the following values:

  • GL_AMBIENT
  • GL_DIFFUSE
  • GL_AMBIENT_AND_DIFFUSE
  • GL_SPECULAR
  • GL_EMISSION

color4f is a float array that specifies red, green blue and alpha values. This values get multiplied by illumination values generated by light sources. This works on a per channel basis, so for example you can have a given color for little shiny dots on your models (specular) and diffuse illumination (‘shading’).

GL_EMISSION lets you specify an absolute illumination value used regardless of light sources being available or not (but I guess still requires lighting to be enabled).

Speculars

You can use GL_SPECULAR and GL_SHININESS to add a kind of shiny spot to your material. Shininess defines the ‘tightness of the spot’:

  • glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 64.0f )

1.0f gives a broad, dull shiny area, 128.0f gives a very tight shiny spot (here I should 64.0f, kind of in the middle)

Caveats

The biggest caveat is that your light source must emit a specular component(!) otherwise your objects won’t display any speculars:

const GLfloat specular[]= {1.0f,1.0f,1.0f,1.0f};

glLightfv(glLightNum, GL_SPECULAR, specular );

Another caveat is that some simulators do not display speculars (at least on Android) so you need to test on device to be sure.