View Full Version : illumination

06-11-2009, 07:53 AM
I've got some problems with setting the lights in my project (using Java opengl bindings).
I'm trying to set up lights to illuminate the whole scene. is there any way to set the intensity of a light (in the infinity)
I set up light0 but still the whole scene is pretty dark.
My code is the following:

float light_pos[] = {-5, -5, -5, 0};
float light_color_am[] = {1, 1, 1};
float light_color_diff[] = {1, 1, 1};
float light_color_spec[] = {1, 1, 1};

gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, light_pos,0);
gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, light_color_am,0);
gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, light_color_diff,0);
gl.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, light_color_spec,0);
gl.glLightf(GL.GL_LIGHT1, GL.GL_SHININESS, 150);
gl.glEnable(GL.GL_LIGHT0);gl.glEnable(GL.GL_LIGHT1 );

the result is the following:

the ground is supposed to be a checkerboard using materials black plastic and white plastic from the following source:
but the fields are displayed really weird...

thank you for your help.

06-11-2009, 09:25 AM
float light_pos[] = {-5, -5, -5, 0};
this is correct for infinite distant light, when the fourth coordinate is = 0, then the 3 first define a direction, not a position.

For the weird display, it looks like your normals are wrong.

06-11-2009, 07:42 PM
normals on the ground should be just {0,1,0}... these are drawn. or am i wrong? I think on the car they're fine...

06-12-2009, 01:43 AM
You should double check your normals, even on the car the shading looks weird. You may try to draw them as lines and will see immediately if they are correct.