PDA

View Full Version : When i open lights, no more color on my objetc



sicklab
12-18-2000, 11:39 AM
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);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

Do i do something wrong?

tanks!

Deiussum
12-18-2000, 12:50 PM
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.

Deiussum
12-18-2000, 12:51 PM
Err... I misread your code. Those properties are for your light color. Do the same thing with the material properties using the glMaterial* functions.

sicklab
12-18-2000, 01:51 PM
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_AMBIENT_AND_DIFFUSE, vCompColor);
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

Deiussum
12-18-2000, 04:27 PM
Yup, that's what I meant. http://www.opengl.org/discussion_boards/ubb/smile.gif Only other idea I have is to check to make sure you're specifying normals correctly.

Marco Costa
11-10-2005, 08:44 AM
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?

Thanks

jide
11-10-2005, 02:08 PM
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.