#### Archived

This topic is now archived and is closed to further replies.

# Lighting problems

This topic is 5742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm having trouble getting lighting to work in program that rotates a cube. All I see is the solid color of my cube, and no shading of any kind. I've read and re-read what to do, and I can't figure out where I'm going wrong... here are the relevant code segments:
void initLighting(void) {
GLfloat mat_properties[] = {1, 1, 0, 1.0};
GLfloat white_light[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_position[] = {5.0, 5.0, -5.0, 1.0 };

glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
glLightfv(GL_LIGHT0, GL_AMBIENT, white_light);

/* object color determined here */
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_properties);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_properties);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}

and in the display callback func:
glBegin(GL_QUADS);
for(int i = 0; i < 6; i++)
{
GLfloat d1[3], d2[3], norm[3];
for(int j = 0; j < 3; j++)
{
d1[j] = vdata[qindices[0]-1][j] - vdata[qindices[i][1]-1][j];
d2[j] = vdata[qindices[i][2]-1][j] - vdata[qindices[i][1]-1][j];
}
normcrossprod(d1,d2,norm);
glNormal3fv(norm);
glVertex3fv(&vdata[qindices[i][0]-1][0]);
glVertex3fv(&vdata[qindices[i][1]-1][0]);
glVertex3fv(&vdata[qindices[i][2]-1][0]);
glVertex3fv(&vdata[qindices[i][3]-1][0]);
}

glEnd();


Thanks edit: there should be an [ i ] after the first qindices, but I don't know how to turn off the codes Edited by - Chupa on March 22, 2002 6:04:47 PM

##### Share on other sites
Well, instead of setting the light to white 1.0,1.0,1.0, try setting it to something like 0.01,0.01,0.01 or so... That oughta do the trick...

Although I''m not sure what the standard of these should be: on one computer I have to set the values to 100 times greater than the original value. So on the one computer I use 10 (x3) and on the other I use 0.01 (x3) with the same graphical result.

Well, I kinda drifted from your problem to my problem but just try setting the amplitude of the color to something way less.

Also try setting the ambient to zero, this way only the light from the source will be applied, and when the source doesn''t reach a face, it must be black (if no other lights are applied)

/G

##### Share on other sites
Its your ambient light. Ambient lighting is basically how much default light you get, whether you are lit by a light or not. Since you set this to 100%, everything will be 100% lit whether its facing the light or not. Try .2, .2, .2 gray instead.

##### Share on other sites
how can i do an enviroment light like inthose quake engines?

##### Share on other sites
your normal is not normalized to length 1.
could be a problem
either normalize it, or glEnable(GL_NORMALIZE) to let gl do it automatically..

##### Share on other sites
Well, besiror. I''m not sure what kind of technic they use in quake to get shadows and nice looking lighting effects. I think it''s lightmap or so, I haven''t seen quake in a long time. If you mean quake 1 I''m almost sure they use only ordinary vertex map...

If you really want state of the art lighting effects, you should check out developer.nvidia.com

/G

##### Share on other sites
My problem was what Gee said, the color was too bright.

Thanks!

• ### Forum Statistics

• Total Topics
628642
• Total Posts
2983985

• 10
• 18
• 20
• 13
• 9