PDA

View Full Version : specular lighting does nott wor



jyoung77
08-08-2007, 04:36 PM
Hi,

The following code intends to test specular lighting but creates a scene totally dark. If I specify some ambient amount for material, I can see the model. Do I do anything wrong? Your help is appreciated. Tony

GLfloat light_position0[] = { 0., 0., 100., 0.0 };
GLfloat light_ambientDiffuse[] = { 0., .02, 0., 1.0};
GLfloat light_specular[] = { 1., 1., 1., 1.0};

glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambientDiffuse);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_ambientDiffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

glEnable(GL_LIGHT0);

GLfloat mat_ambientDiffuse[] = { 0.0, 0.0, 0.0, 1.0};
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 60.0 };
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_ambientDiffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);

Trenki
08-09-2007, 01:44 AM
Since you specify a black color for ambient and diffuse the model will not be visible. Your specular setup looks fine as far as i can tell.
Whether specular highlights show up depends on your model and camera and light setup.
You specify a directional lightsource as w is 0 for light_position0. Maybe you can try could try -100 instead of 100 for you z coordinate in the light position and see if it changes anything (Don't know whether for directional lights position specifies a direction vector towards the origin or away from it)

Jon723
08-09-2007, 08:26 AM
Did you by chance enable lighting by setting glEnable(GL_LIGHTING); ??

jyoung77
08-09-2007, 11:09 AM
I intended to make ambient and diffuse inactive so that I can observe specular highlights independently. I also tried -100 as you said but nothing shows up. I tried to increase some amount to mat_ambientDiffuse and then the model showed up. It meant that the camera and light setup was ok, right?

Tony

V-man
08-10-2007, 05:13 PM
Maybe you need to call
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);

If you aren't using texturing, that call doesn't matter.

Also, remember that GL does per vertex lighting so it could be the reason why you won't see the specular highlight. It's best to make a highly detailed sphere in this case and it will be visible.

dorbie
08-19-2007, 12:11 AM
As V-man says, that exponent of 60 will give you a very small highlight which may miss a vertex.

You could also try lowering the exponent to give you a broader specular highlight.