glColorMaterial

When you''re using lighting, OpenGL needs material properties to determine what color of light is reflected from a surface. You can specify these properties for ambient, diffuse, and specular light with glMaterial*, or you can let OpenGL create them for you. If you pass GL_COLOR_MATERIALS to glEnable(), OpenGL will automatically set material properties based on the current color ( glColor*() ). Using glColorMaterial is like a compromise between the two. If you use glColorMaterial, you can still pass values to glMaterial*, but it will disregard the value specified in glColorMaterial. For instance...

glEnable(GL_COLOR_MATERIAL); // Must be called to use glColorMaterial()
glColorMaterial(GL_FRONT, GL_DIFFUSE);

tells OpenGL to create material properties for diffuse light on the front of objects using the current color. All other material properties still need to be specified with glMaterial*.

There''s a good explanation in the Red Book, in the lighting chapter (chapter 5).

你可能感兴趣的:(color)