LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: DavidYazel on July 05, 2003, 03:34:07

Title: Lighting
Post by: DavidYazel on July 05, 2003, 03:34:07
I am getting some really strange things happening in lighting.  I have one ambient light:


       Color3f c = leaf.getColor();
       floatBuffer4.clear();
       floatBuffer4.put(c.x);
       floatBuffer4.put(c.y);
       floatBuffer4.put(c.z);
       floatBuffer4.put(1);
       gl.lightModelfv(GL.LIGHT_MODEL_AMBIENT, floatBuffer4Addr);
       gl.lightfv(GL.LIGHT0, GL.AMBIENT, floatBuffer4Addr);
       gl.enable(GL.LIGHT0);


and one material


               gl.enable(GL.LIGHTING);
               gl.materiali(GL.FRONT_AND_BACK, GL.SHININESS,
                            (int) material.getShininess());

               Color3f c = material.getAmbientColor();
               floatBuffer4.clear();
               floatBuffer4.put(c.x);
               floatBuffer4.put(c.y);
               floatBuffer4.put(c.z);
               floatBuffer4.put(1f); // 1.0 is the alpha
               gl.materialf(GL.FRONT, GL.AMBIENT, floatBuffer4Addr);


the ambient color is 0.2,0.2,02 and the ambient material is 1,1,1

There are vertex colors of different kinds also.

So this is what is happening.

1. The vertex colors are being completely ignored
2. The objects are shown in pure white
3. When I rotate the object it gets darker and darker and then snaps back to white.

If I disable lighting then my vertex colors work.  There is no directional light, just this one ambient one, so I can't understand why the color changes as it rotates.  

Are there any LWJGL bugs in lighting?  Any possibility that GL.AMBIENT is the wrong value?
Title: Lighting
Post by: DavidYazel on July 05, 2003, 04:08:46
Ok one problem is that I needed to enable:

gl.enable(GL.COLOR_MATERIAL);

This now has the material * vertex color.

But the colors are now going from correct to pure white and back again as the object rotates.

I should not need to set a light position for ambient light right?
Title: Lighting
Post by: DavidYazel on July 05, 2003, 04:49:32
Got it!  For some reason I have to use LIGHT1 and not LIGHT0.

Works like a champ now!

Dave
Title: Lighting
Post by: cfmdobbie on July 05, 2003, 09:06:43
There's one difference between LIGHT0 and any other light - the defaults are different for the Diffuse and Specular components.  LIGHT0 has these both set to (1, 1, 1, 1) while the rest have them set to (0, 0, 0, 0).  This is probably the root of your problem.
Title: Beautification
Post by: Matzon on July 05, 2003, 10:38:28
to lessen the eye pain of all the put's - you could do:

floatBuffer4.clear();
floatBuffer4.put(c.x).put(c.y).put(c.z);.put(1f);
Title: Lighting
Post by: princec on July 05, 2003, 11:01:50
or even

floarBuffer4.clear();
floatBuffer4.put(new float[] {c.x, c.y, c.z, 1.0f});

But that might not be so good in a rendering loop because of the new().

Cas :)
Title: Re: Beautification
Post by: oNyx on July 06, 2003, 00:39:06
Quote from: "Matzon"to lessen the eye pain of all the put's - you could do:

floatBuffer4.clear();
floatBuffer4.put(c.x).put(c.y).put(c.z);.put(1f);

/me points at the first ';' in the 2nd line :>
Title: Lighting
Post by: princec on July 06, 2003, 10:06:15
Must fix that horrible orange colour. I can hardly read it.

Cas :)
Title: Lighting
Post by: cfmdobbie on July 06, 2003, 11:40:48
Could be worse...
Title: lol
Post by: Matzon on July 06, 2003, 11:47:46
yeah it could! LOL
Title: ffs
Post by: Matzon on July 06, 2003, 11:48:45
ARGH of course my white text gets positioned in the grey one !!! luckily this means that this must be a white one good thing :)