LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: elias4444 on March 07, 2005, 17:02:37

Title: How do you clear out lights?
Post by: elias4444 on March 07, 2005, 17:02:37
I've been running into a problem reusing lights between different game scenes (e.g., GL_LIGHT1). It seems to retain whatever information I gave it from the scene before (like if the first scene used specular lighting, but in the second scene, I don't want it to). I'm using the following command sequence to clear the screen each frame:

GL11.glClearColor(0,0,0,0);
GL11.glClearDepth(1.0);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glLoadIdentity();

Is there one to clear out the "light buffers"?
Title: How do you clear out lights?
Post by: Orangy Tang on March 07, 2005, 17:08:29
You can glEnable/Disable each LIGHT_1 etc. as needed. Lights are OpenGL state and persist just like current blend mode etc.
Title: How do you clear out lights?
Post by: elias4444 on March 07, 2005, 17:13:53
I'm going through my code, and realizing that it may not in fact be the light's fault... I keep getting specular light when I don't want it, which seems to be related to the glMaterial call I'm making:
      GL11.glMaterial(GL11.GL_FRONT,GL11.GL_SPECULAR,(FloatBuffer)materialtemp.asFloatBuffer().put(materialSpecular).flip());
GL11.glMaterial(GL11.GL_FRONT,GL11.GL_SHININESS,(FloatBuffer)materialtemp.asFloatBuffer().put(materialShininess).flip());
GL11.glMaterial(GL11.GL_FRONT,GL11.GL_DIFFUSE,(FloatBuffer)materialtemp.asFloatBuffer().put(materialDiffuse).flip());
GL11.glMaterial(GL11.GL_FRONT,GL11.GL_AMBIENT,(FloatBuffer)materialtemp.asFloatBuffer().put(materialAmbient).flip());

So, I guess my question should have been: How do you turn off the Material flag, so as to disable specular effects from once scene to another. Even if I don't call the glMaterial functions, they seem to carry over from frame to frame, or scene to scene.
Title: How do you clear out lights?
Post by: Orangy Tang on March 07, 2005, 17:37:50
You could easily set the specular material colour to black. Since specular is added ('cos its basically a reflection) that'll mean it has no effect.
Title: How do you clear out lights?
Post by: napier on March 07, 2005, 20:54:48
The specular material property can be set to black.  Other material properties can be set back to default values.  As far as I know you can't turn off materials.  By default the material diffuse and ambient colors are shades of gray.

I use a function like this to clear material settings:

   public void clearMaterial() {
       GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT, noAmbient);  // 0.2f, 0.2f, 0.2f, 1f
       GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, noDiffuse);  // 0.8f, 0.8f, 0.8f, 1f
       GL11.glMaterial(GL11.GL_FRONT, GL11.GL_EMISSION, noColor);   // 0,0,0,1
       GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, noColor);   // 0,0,0,1
       GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SHININESS, noShine ); // 0,0,0,0
   }


The arguments (noAmbient, noColor, noShine) are floatbuffers that contain the commented values.