From 87ee7df1a60d31e67ecdf347a6178f116f8d9133 Mon Sep 17 00:00:00 2001 From: juniperoserra Date: Wed, 6 Apr 2005 21:29:28 +0000 Subject: [PATCH] Lights() now sets up default lighting, which is a slight ambient light and a medium directional light pointing down the Z axis. --- core/PApplet.java | 12 ++++++++++++ core/PGraphics.java | 8 ++++++++ core/PGraphics3.java | 21 ++++++++++++--------- opengl/PGraphicsGL.java | 6 +++--- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/core/PApplet.java b/core/PApplet.java index a3dbb6eaa..1b16f09c0 100644 --- a/core/PApplet.java +++ b/core/PApplet.java @@ -5683,6 +5683,18 @@ v PApplet.this.stop(); } + public void clearLights() { + if (recorder != null) recorder.clearLights(); + g.clearLights(); + } + + + public void defaultLights() { + if (recorder != null) recorder.defaultLights(); + g.defaultLights(); + } + + public void light(int num, float x, float y, float z, float red, float green, float blue) { if (recorder != null) recorder.light(num, x, y, z, red, green, blue); diff --git a/core/PGraphics.java b/core/PGraphics.java index e13c4b1bf..695c694ea 100644 --- a/core/PGraphics.java +++ b/core/PGraphics.java @@ -2072,6 +2072,14 @@ public class PGraphics extends PImage implements PConstants { throw new RuntimeException("noLights() can only be used with depth()"); } + public void clearLights() { + throw new RuntimeException("clearLights() can only be used with depth()"); + } + + public void defaultLights() { + throw new RuntimeException("defaultLights() can only be used with depth()"); + } + public void light(int num, float x, float y, float z, float red, float green, float blue) { throw new RuntimeException("light() can only be used with depth()"); diff --git a/core/PGraphics3.java b/core/PGraphics3.java index 0929dcb6a..bf6d841c6 100644 --- a/core/PGraphics3.java +++ b/core/PGraphics3.java @@ -326,24 +326,26 @@ public class PGraphics3 extends PGraphics { triangle = new PTriangle(this); } - protected void resetLights() { - // reset lights - // This looks like a funny reset, but it's to make the most common - // case the easiest to attain even if the user chooses to do everything - // by hand. + public void clearLights() { lightCount = 0; light[0] = false; - lightType[0] = AMBIENT; - for (int i = 1; i < MAX_LIGHTS; i++) { + for (int i = 0; i < MAX_LIGHTS; i++) { light[i] = false; - lightType[i] = POINT; } } + + public void defaultLights() { + clearLights(); + createAmbientLight(60); + createDirectionalLight(80, 80, 80, 0, 0, -1); + } public void beginFrame() { super.beginFrame(); - resetLights(); + if (lights) { + defaultLights(); + } // reset lines lineCount = 0; @@ -2678,6 +2680,7 @@ public class PGraphics3 extends PGraphics { public void lights() { lights = true; + defaultLights(); } public void noLights() { diff --git a/opengl/PGraphicsGL.java b/opengl/PGraphicsGL.java index 39f135f9b..7c8e63151 100644 --- a/opengl/PGraphicsGL.java +++ b/opengl/PGraphicsGL.java @@ -136,7 +136,7 @@ public class PGraphicsGL extends PGraphics3 { canvas.setNoAutoRedrawMode(true); // maybe this will help? - canvas.requestFocus(); + //canvas.requestFocus(); // done with this business displayed = true; @@ -204,8 +204,8 @@ public class PGraphicsGL extends PGraphics3 { } - protected void resetLights() { - super.resetLights(); + public void clearLights() { + super.clearLights(); for (int i = 0; i < MAX_LIGHTS; i++) { lightDisable(i); }