We draw a scene and then, using the keyboard, we re-position the source of the light. This far everything is great. Now, as long as we use diffuse light all is just fine but as soon as we change to specular light, the scene behaves unpredictably. At first we suspected the normals to be crazy but it does work as expected with diffuse light, so, we assume it can’t be that. Most likely, it’s something basic but as far as we have seen the examples and help given in the Red Book, it’s suppsoed to work (and it does work as well but not for all the faces).
The diffuse light works for all our faces (we have only three this far) while the specular light works for the first two but not the third. The first two are in the xy-plane, while the third one is in the xz-plane. And (once again), yes, we did set the normal right (correct behavior of the difufse light proves it).
This is how we set up the object.
private void doDrawStupidThingThatWorksNotWithLight () {
double size = 75.0;
float[]
amb = new float[]{0.0f, 1.0f, 0.0f, 1.0f},
dif = new float[]{0.0f, 1.0f, 0.0f, 1.0f},
spe = new float[]{0.0f, 1.0f, 0.0f, 1.0f},
shi = new float[]{50.0f};
this.gl.glMaterialfv (GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, amb);
this.gl.glMaterialfv (GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, dif);
this.gl.glMaterialfv (GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, spe);
this.gl.glMaterialfv (GL.GL_FRONT, GL.GL_SHININESS, shi);
this.gl.glBegin (GL.GL_QUADS);
this.gl.glNormal3d (0, 1, 0);
this.gl.glVertex3d (0, 0, 0);
this.gl.glVertex3d (0, 0, size);
this.gl.glVertex3d (-size, 0, size);
this.gl.glVertex3d (-size, 0, 0);
this.gl.glEnd ();}
And this is how we set up the lighting.
private void doShedLight () {
float[]
amb = new float[]{0.2f, 0.2f, 0.2f, 1.0f},
dif = new float[]{0.0f, 0.0f, 0.0f, 1.0f},
spe = new float[]{1.0f, 1.0f, 1.0f, 1.0f},
pos = new float[]{this.angX, this.angY, this.angZ, 0.0f},
spo = new float[]{0.0f, 0.0f, 0.0f, 1.0f};
this.gl.glLightfv (GL.GL_LIGHT0, GL.GL_AMBIENT, amb);
this.gl.glLightfv (GL.GL_LIGHT0, GL.GL_DIFFUSE, dif);
this.gl.glLightfv (GL.GL_LIGHT0, GL.GL_SPECULAR, spe);
this.gl.glLightfv (GL.GL_LIGHT0, GL.GL_POSITION, pos);
this.gl.glLightfv (GL.GL_LIGHT0, GL.GL_SPOT_DIRECTION, spo); }
So, any hints?