When i open lights, no more color on my objetc

I have a blue cube. Well, it is blue until i set up a light. When i have at least one light open, my cube get the color of my Light.

Here is how i initialize my lighting:

GLfloat	ambientProperties[]  = {0.7f, 0.7f, 0.7f, 1.0f};
GLfloat	diffuseProperties[]  = {0.8f, 0.8f, 0.8f, 1.0f};
GLfloat	specularProperties[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat	positionProperties[] = {1.0f, 1.0f, 1.0f, 0.0f};

glClearDepth( 1.0 );

glLightfv( GL_LIGHT0, GL_AMBIENT, ambientProperties);
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseProperties);
glLightfv( GL_LIGHT0, GL_SPECULAR, specularProperties);
glLightfv( GL_LIGHT0, GL_POSITION, positionProperties);
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0);


Do i do something wrong?


When you enable lighting, the color is determined by the current material properties, not the current color. Your material’s ambient and diffuse properties are a light gray, and your specular highlights are pure white. If you want it blue, try setting the diffuse and ambient material properties to blue.

Err… I misread your code. Those properties are for your light color. Do the same thing with the material properties using the glMaterial* functions.

Tanks for answering!

Here is what i do each time i draw a component:

  static GLfloat vCompColor[4];
  vCompColor[0] = (float) GetRValue(rgbColComp) / 255.0f;
  vCompColor[1] = (float) GetGValue(rgbColComp) / 255.0f;
  vCompColor[2] = (float) GetBValue(rgbColComp) / 255.0f;
  vCompColor[3] = 1.0f;

  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vCompColor);

  glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0f);

is that what you means?

if so… sill no color when light are on…

I am sure it is something ridiculous… i just can’t get it…

tanks again, hoping you have another idea

Yup, that’s what I meant. Only other idea I have is to check to make sure you’re specifying normals correctly.

Let me see if I got this right. Soo, if you´re basically gonna use lighting for all your scenes, you can basically throw glColor out the window and stick with glMaterial?


That’s the way, right. But also be sure your light will ‘light up’ your scene and not the void and that it matches what you wanted (directional vs positional lights). Also ensure you specify normals (not needed with most of glut drawing routines like glutSolidCube) and that they are normalized.
Finally, check that the intensities of lights and materials are suffisant enough to see something.

That would be okay then.