Original Post
Hi!,
I have a cube rotating and wanted to add shading to it. But with the following code (though the cube is colored), only white (or gray, or almost black) quad appear (depeding on the light setting). Here''s the init code:
If you find the problem, please post the solution here, thanks a lot.
glEnable(GL_LIGHTING);
GLfloat diffusive_light[]={1.0f,0.7f,0.7f,1.0f};
GLfloat ambient_light[]={0.4f,0.4f,0.4f,0.4f,1.0f};
GLfloat position[]={0.0f,0.0f,3.0f,1.0f};
GLfloat all[]={1.0f,1.0f,1.0f,1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient_light);
glShadeModel(GL_SMOOTH);
glLightfv(GL_LIGHT1,GL_AMBIENT,ambient_light);
glLightfv(GL_LIGHT1,GL_DIFFUSE,diffusive_light);
glLightfv(GL_LIGHT1,GL_SPECULAR,diffusive_light);
glLightfv(GL_LIGHT1,GL_POSITION,position);
glEnable(GL_LIGHT1);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,all);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,all);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
//and here the main loop with cube painting comes,
//I have correct normals selected and the vertices
//colored.