From 65f8e12c97e93064f0bae980ba8a433d155febe9 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 21 Nov 2012 01:21:18 +0000 Subject: [PATCH] sets the ambient color in PShapeOpenGL when setting fill for the first time, fixes issue 1342 --- .../core/src/processing/core/PGraphics.java | 2 +- android/core/src/processing/core/PShape.java | 1 + .../processing/opengl/PGraphicsOpenGL.java | 2 ++ .../src/processing/opengl/PShapeOpenGL.java | 11 ++++++++++ core/src/processing/core/PGraphics.java | 2 +- core/src/processing/core/PShape.java | 21 ++++++++++--------- .../processing/opengl/PGraphicsOpenGL.java | 2 ++ core/src/processing/opengl/PShapeOpenGL.java | 11 ++++++++++ 8 files changed, 40 insertions(+), 12 deletions(-) diff --git a/android/core/src/processing/core/PGraphics.java b/android/core/src/processing/core/PGraphics.java index 296710d61..4d8b45990 100644 --- a/android/core/src/processing/core/PGraphics.java +++ b/android/core/src/processing/core/PGraphics.java @@ -419,7 +419,7 @@ public class PGraphics extends PImage implements PConstants { public int ambientColor; public float ambientR, ambientG, ambientB; - protected boolean setAmbient; + public boolean setAmbient; public int specularColor; public float specularR, specularG, specularB; diff --git a/android/core/src/processing/core/PShape.java b/android/core/src/processing/core/PShape.java index 86bb9d59b..514507ede 100644 --- a/android/core/src/processing/core/PShape.java +++ b/android/core/src/processing/core/PShape.java @@ -144,6 +144,7 @@ public class PShape implements PConstants { protected int tintColor; protected int ambientColor; + protected boolean setAmbient; protected int specularColor; protected int emissiveColor; protected float shininess; diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index 3b9b9d878..73fc2f5b7 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -4734,6 +4734,8 @@ public class PGraphicsOpenGL extends PGraphics { // default ambient color when the user doesn't specify // it explicitly. ambientFromCalc(); + // ambientFromCalc sets setAmbient to true, but it hasn't been + // set by the user so put back to false. setAmbient = false; } } diff --git a/android/core/src/processing/opengl/PShapeOpenGL.java b/android/core/src/processing/opengl/PShapeOpenGL.java index 2f6053e8c..6201f66a9 100644 --- a/android/core/src/processing/opengl/PShapeOpenGL.java +++ b/android/core/src/processing/opengl/PShapeOpenGL.java @@ -339,6 +339,7 @@ public class PShapeOpenGL extends PShape { tint = pg.tint; tintColor = pg.tintColor; + setAmbient = pg.setAmbient; ambientColor = pg.ambientColor; specularColor = pg.specularColor; emissiveColor = pg.emissiveColor; @@ -1265,6 +1266,15 @@ public class PShapeOpenGL extends PShape { protected void fillFromCalc() { fill = true; updateFillColor(calcColor); + + if (!setAmbient) { + // Setting the ambient color from the current fill + // is what the old P3D did and allows to have an + // default ambient color when the user doesn't specify + // it explicitly. + ambientFromCalc(); + setAmbient = false; + } } @@ -1636,6 +1646,7 @@ public class PShapeOpenGL extends PShape { protected void ambientFromCalc() { updateAmbientColor(calcColor); + setAmbient = true; } diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index 07466e4bf..641dddede 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -445,7 +445,7 @@ public class PGraphics extends PImage implements PConstants { public int ambientColor; public float ambientR, ambientG, ambientB; - protected boolean setAmbient; + public boolean setAmbient; public int specularColor; public float specularR, specularG, specularB; diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index 757be3e59..22307ebc9 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -146,6 +146,7 @@ public class PShape implements PConstants { protected int tintColor; protected int ambientColor; + protected boolean setAmbient; protected int specularColor; protected int emissiveColor; protected float shininess; @@ -475,14 +476,14 @@ public class PShape implements PConstants { } /** - * @webref pshape:method + * @webref pshape:method * @brief Starts a new contour */ public void beginContour() { } - + /** - * @webref pshape:method + * @webref pshape:method * @brief Ends a contour */ public void endContour() { @@ -505,7 +506,7 @@ public class PShape implements PConstants { /** * @webref pshape:method - * @brief Finishes the creation of a new PShape + * @brief Finishes the creation of a new PShape */ public void end() { } @@ -1296,7 +1297,7 @@ public class PShape implements PConstants { // can't be just 'add' because that suggests additive geometry /** * @webref pshape:method - * @brief Adds a new child + * @brief Adds a new child */ public void addChild(PShape who) { if (children == null) { @@ -1460,7 +1461,7 @@ public class PShape implements PConstants { } /** - * @webref pshape:method + * @webref pshape:method * @brief Returns the total number of vertices as an int */ public int getVertexCount() { @@ -1469,7 +1470,7 @@ public class PShape implements PConstants { /** - * @webref pshape:method + * @webref pshape:method * @brief Returns the vertex at the index position * @param index the location of the vertex */ @@ -1506,7 +1507,7 @@ public class PShape implements PConstants { } /** - * @webref pshape:method + * @webref pshape:method * @brief Sets the vertex at the index position * @param index the location of the vertex * @param x the x value for the vertex @@ -1519,7 +1520,7 @@ public class PShape implements PConstants { /** * @param z the z value for the vertex - */ + */ public void setVertex(int index, float x, float y, float z) { vertices[index][X] = x; vertices[index][Y] = y; @@ -1528,7 +1529,7 @@ public class PShape implements PConstants { /** * @param vec the PVector to define the x, y, z coordinates - */ + */ public void setVertex(int index, PVector vec) { vertices[index][X] = vec.x; vertices[index][Y] = vec.y; diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index fe75c9594..adb7d8ba4 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -4721,6 +4721,8 @@ public class PGraphicsOpenGL extends PGraphics { // default ambient color when the user doesn't specify // it explicitly. ambientFromCalc(); + // ambientFromCalc sets setAmbient to true, but it hasn't been + // set by the user so put back to false. setAmbient = false; } } diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 9512fb65b..172b2225c 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -339,6 +339,7 @@ public class PShapeOpenGL extends PShape { tint = pg.tint; tintColor = pg.tintColor; + setAmbient = pg.setAmbient; ambientColor = pg.ambientColor; specularColor = pg.specularColor; emissiveColor = pg.emissiveColor; @@ -1265,6 +1266,15 @@ public class PShapeOpenGL extends PShape { protected void fillFromCalc() { fill = true; updateFillColor(calcColor); + + if (!setAmbient) { + // Setting the ambient color from the current fill + // is what the old P3D did and allows to have an + // default ambient color when the user doesn't specify + // it explicitly. + ambientFromCalc(); + setAmbient = false; + } } @@ -1636,6 +1646,7 @@ public class PShapeOpenGL extends PShape { protected void ambientFromCalc() { updateAmbientColor(calcColor); + setAmbient = true; }