Hi, I’m learning to use opengl, and I can’t figure out how to have polygons that are colored and have lighting. As soon as I enable a light source everything becomes white.
The only thing I can think of is texture mapping a plain color… but isn’t this inefficient?
enabling materials seemed to make the colors work… although I do not see a difference when I change the values sent to glMaterialf or even if I do not call it. I wanted to render a sphere and have that little shiny part…
After enabling lightinng and GL_COLOR_MATERIAL, apply specular colour and shininess on your model.
For example;
// track material ambient and diffuse from vertex color
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
...
// specify material color of an object
GLfloat shininess = 50; // range 0 ~ 128
GLfloat specularColor[4] = {1,1,1,1}; // white
GLfloat diffuseColor[3] = {1,0,0}; // red
// set specular and shiniess
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularColor);
// set ambient and diffuse color
glColor3fv(diffuseColor);
...
It renders reddish body with white spot for specular reflection.