diff --git a/app/PdeBase.java b/app/PdeBase.java
index 5261a240a..eb686c3fa 100644
--- a/app/PdeBase.java
+++ b/app/PdeBase.java
@@ -45,7 +45,7 @@ import com.ice.jni.registry.*;
* files and images, etc) that comes from that.
*/
public class PdeBase {
- static final String VERSION = "0077 Alpha";
+ static final String VERSION = "0078 Alpha";
static String openedAtStartup;
diff --git a/app/PdeSketch.java b/app/PdeSketch.java
index bb05c3455..eb7666ffd 100644
--- a/app/PdeSketch.java
+++ b/app/PdeSketch.java
@@ -1278,6 +1278,20 @@ public class PdeSketch {
importedLibraries.add(libFolder);
libraryPath += File.pathSeparator + libFolder.getAbsolutePath();
+
+ /*
+ String list[] = libFolder.list();
+ if (list != null) {
+ for (int j = 0; j < list.length; j++) {
+ // this might have a dll/jnilib/so packed,
+ // so add it to the library path
+ if (list[j].toLowerCase().endsWith(".jar")) {
+ libraryPath += File.pathSeparator +
+ libFolder.getAbsolutePath() + File.separator + list[j];
+ }
+ }
+ }
+ */
}
diff --git a/app/PdeSketchbook.java b/app/PdeSketchbook.java
index 72bbe8953..953014969 100644
--- a/app/PdeSketchbook.java
+++ b/app/PdeSketchbook.java
@@ -279,7 +279,7 @@ public class PdeSketchbook {
fd.setFilenameFilter(new FilenameFilter() {
public boolean accept(File dir, String name) {
//System.out.println("check filter on " + dir + " " + name);
- return name.endsWith(".pde");
+ return name.toLowerCase().endsWith(".pde");
}
});
diff --git a/build/shared/bugs.txt b/build/shared/bugs.txt
index 4b6b2fcb2..8c8dfdc76 100644
--- a/build/shared/bugs.txt
+++ b/build/shared/bugs.txt
@@ -180,6 +180,12 @@ OPENGL PROBLEMS
have this graphics chipset on your machine before installing.
(thanks to Daniel Shiffman for finding this fix!)
+- on macosx, i don't think there's much we can do about the following error:
+ Error: view not ready, cannot lock focus at
+ "/Users/kbr/JavaNet/jogl/src/native/jogl/
+ MacOSXWindowSystemInterface.m:createContext:51"
+ this shows up sometimes on run, just hit run again and things oughta work.
+
- on windows, if you're getting a lot of opengl crashing, blue screens,
or other mess, your driver might be bad. if you're using a dell, use
the driver they provide (support.dell.com) instead of what might be a
diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt
index 6a0851a04..9a294c096 100644
--- a/build/shared/revisions.txt
+++ b/build/shared/revisions.txt
@@ -7,23 +7,47 @@ releases will be super crusty.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
-ABOUT REV 0078
+ABOUT REV 0078 - 30 March 2005
-bug fixes:
+this release includes a large number of fixes for the 2D graphics engine.
+nothing has changed in the processing 3D engine (what you get when you
+call depth()), however the OpenGL renderer now supports loadPixels(),
+updatePixels(), saveFrame(), get(), and pmouseX/Y.
-- lines of text were getting mashed together both horizontally and
- vertically. the font stuff was moved around a lot in 0077 and so
- this made a mess of things.
+around the corner are big fixes to 3D when simon finishes the new
+lighting model. he's moving through it pretty quickly so we hope to have
+it in a release shortly.
-- backwards rectangles and ellipses are now drawn properly. (i.e.
- rectangles where (x2 < x1) or (y2 < y1), or ellipses with a
- negative width or height).
-- same thing for backwards images, note that an image drawn backwards
- won't actually flip the image or anything nutty like that.
+major things still not solved since last release:
+
+- still lots of threading/flickering strangeness
+
+- applet not being placed properly inside its window
+
+- things sometims not starting up (gives a cryptic error in the console)
+
+- text inside a rect is slightly broken
+
+- you can't do per-vertex coloring of lines in 2D
+
+- everything else not covered here that was broken in 77...
+
api changes:
+- fun things: some of the filter() stuff in PImage now works:
+ + filter(GRAY) will convert a PImage to grayscale.
+ + filter(INVERT) will invert an image
+ + filter(POSTERIZE, int levels) will posterize to that many levels
+ + filter(THRESHOLD) or filter(THRESHOLD, float midpoint)
+ will give you a black and white image, with optionally settable
+ midpoint (a value from 0 to 1)
+ + coming soon is filter(BLUR) and filter(BLUR, float radius)...
+
+- strokeCap/strokeJoin constants for MITERED is now MITER, BEVELED is BEVEL,
+ and PROJECTED is now PROJECT.
+
- as of 0077, font.width() works differently. it returns the width of
a one point font, not the font at its current size. the font api
built into PGraphics/PApplet now consists of:
@@ -43,6 +67,60 @@ api changes:
text, you should use textWidth() or textAscent() in PGraphics/PApplet
which will return values based on what was set in textSize().
+- bezierVertex has changed. instead of four calls to bezierVertex,
+ you should instead use:
+ vertex(x1, y1);
+ bezierVertex(x2, y2, x3, y3, x4, y4);
+ this helps iron out some inconsistencies that you get with the wrong
+ number of bezierVertex coords. it also prevents you from having to
+ double up the final coordinate to draw the next segment.
+
+- got rid of CONCAVE_POLYGON and CONVEX_POLYGON since they never really
+ came into full use.
+
+
+bug fixes:
+
+- curveVertex works again.
+
+- lines of text were getting mashed together both horizontally and
+ vertically. the font stuff was moved around a lot in 0077 and so
+ this made a mess of things.
+
+- backwards rectangles and ellipses are now drawn properly. (i.e.
+ rectangles where (x2 < x1) or (y2 < y1), or ellipses with a
+ negative width or height).
+
+- same thing for backwards images, note that an image drawn backwards
+ won't actually flip the image or anything nutty like that.
+
+- the file open dialog on macosx now lets you open files ending
+ with all caps .PDE instead of .pde
+
+- imageMode() was broken
+
+- loadPixels, updatePixels, save, and saveFrame were totally broken
+ and now they work in both the Java2D and OpenGL renderers.
+
+- patched in the latest version of jogl to hopefully fix some of the
+ overly chatty error messages.
+
+- SCREEN_SPACE text is working again
+
+- tint() is now working properly, except that it ignores colors (but
+ accepts alpha) with PGraphics3 (processing renderer with depth())
+
+- arc was broken and inconsistent, now fixed.
+
+- several bug fixes inside Camera and Movie.
+
+- PImage.get() had a bug where it wouldn't properly read data as
+ you neared or crossed any of the edges of the image.
+
+- bug in the gl renderer that had images drawing the wrong size/shape.
+
+- default strokeCap and strokeJoin now set.
+
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
diff --git a/core/PApplet.java b/core/PApplet.java
index 7c829a0d4..7db0999be 100644
--- a/core/PApplet.java
+++ b/core/PApplet.java
@@ -317,6 +317,8 @@ public class PApplet extends Applet
public void stop() {
//finished = true; // why did i comment this out?
+ //System.out.println("stopping applet");
+
// don't run stop and disposers twice
if (thread == null) return;
thread = null;
@@ -458,6 +460,7 @@ public class PApplet extends Applet
public void draw() {
// if no draw method, then shut things down
+ //System.out.println("no draw method, goodbye");
finished = true;
}
@@ -615,6 +618,7 @@ public class PApplet extends Applet
*/
while ((Thread.currentThread() == thread) && !finished) {
+ //while ((thread != null) && !finished) {
//while (!finished) {
//updated = false;
@@ -764,7 +768,10 @@ public class PApplet extends Applet
// note that this will not catch errors inside setup()
// those are caught by the PdeRuntime
+ System.out.println("exception occurred (if you don't see a stack " +
+ "trace below this message, we've got a bug)");
finished = true;
+ //e.printStackTrace(System.out);
if (leechErr != null) {
// if draw() mode, make sure that ui stops waiting
@@ -779,6 +786,7 @@ public class PApplet extends Applet
}
if (THREAD_DEBUG) println(Thread.currentThread().getName() +
" thread finished");
+ //System.out.println("exiting run " + finished);
stop(); // call to shutdown libs?
}
@@ -3171,6 +3179,7 @@ public class PApplet extends Applet
}
+
//////////////////////////////////////////////////////////////
// STRINGS
@@ -4093,10 +4102,14 @@ public class PApplet extends Applet
int anything = System.in.read();
if (anything == EXTERNAL_STOP) {
+ //System.out.println("got external stop");
+
// adding this for 0073.. need to stop libraries
// when the stop button is hit.
PApplet.this.stop();
finished = true;
+ //} else {
+ //print((char) anything);
}
} catch (IOException e) {
finished = true;
@@ -4444,6 +4457,26 @@ v PApplet.this.stop();
}
+ //////////////////////////////////////////////////////////////
+
+
+ public void loadPixels() {
+ g.loadPixels();
+ pixels = g.pixels;
+ }
+
+
+ public void updatePixels() {
+ // anything special here?
+ g.updatePixels();
+ }
+
+
+ public void updatePixels(int x1, int y1, int x2, int y2) {
+ g.updatePixels(x1, y1, x2, y2);
+ }
+
+
//////////////////////////////////////////////////////////////
// everything below this line is automatically generated. no touch.
@@ -4468,24 +4501,6 @@ v PApplet.this.stop();
}
- public void loadPixels() {
- if (recorder != null) recorder.loadPixels();
- g.loadPixels();
- }
-
-
- public void updatePixels() {
- if (recorder != null) recorder.updatePixels();
- g.updatePixels();
- }
-
-
- public void updatePixels(int x1, int y1, int x2, int y2) {
- if (recorder != null) recorder.updatePixels(x1, y1, x2, y2);
- g.updatePixels(x1, y1, x2, y2);
- }
-
-
public int get(int x, int y) {
return g.get(x, y);
}
@@ -4496,6 +4511,11 @@ v PApplet.this.stop();
}
+ public PImage get() {
+ return g.get();
+ }
+
+
public void set(int x, int y, int c) {
if (recorder != null) recorder.set(x, y, c);
g.set(x, y, c);
@@ -4686,15 +4706,19 @@ v PApplet.this.stop();
}
- public void bezierVertex(float x, float y) {
- if (recorder != null) recorder.bezierVertex(x, y);
- g.bezierVertex(x, y);
+ public void bezierVertex(float x1, float y1,
+ float x2, float y2,
+ float x3, float y3) {
+ if (recorder != null) recorder.bezierVertex(x1, y1, x2, y2, x3, y3);
+ g.bezierVertex(x1, y1, x2, y2, x3, y3);
}
- public void bezierVertex(float x, float y, float z) {
- if (recorder != null) recorder.bezierVertex(x, y, z);
- g.bezierVertex(x, y, z);
+ public void bezierVertex(float x1, float y1, float z1,
+ float x2, float y2, float z2,
+ float x3, float y3, float z3) {
+ if (recorder != null) recorder.bezierVertex(x1, y1, z1, x2, y2, z2, x3, y3, z3);
+ g.bezierVertex(x1, y1, z1, x2, y2, z2, x3, y3, z3);
}
@@ -5458,12 +5482,6 @@ v PApplet.this.stop();
}
- public void clear() {
- if (recorder != null) recorder.clear();
- g.clear();
- }
-
-
public final float alpha(int what) {
return g.alpha(what);
}
diff --git a/core/PConstants.java b/core/PConstants.java
index 156a4d849..14c5f024f 100644
--- a/core/PConstants.java
+++ b/core/PConstants.java
@@ -83,12 +83,13 @@ public interface PConstants {
// filter/convert types
- static final int BLACK_WHITE = 10;
- static final int GRAYSCALE = 11;
- static final int BLUR = 12;
- static final int GAUSSIAN_BLUR = 13;
- static final int POSTERIZE = 14;
- static final int FIND_EDGES = 15;
+ static final int BLUR = 12;
+ //static final int EDGES = 15; // removed
+ static final int GRAY = 11;
+ static final int INVERT = 13;
+ static final int POSTERIZE = 14;
+ static final int THRESHOLD = 10;
+ // RGB is also a filter option
// blend mode keyword definitions
@@ -156,8 +157,8 @@ public interface PConstants {
static final int QUAD_STRIP = (1 << 7) | 1;
static final int POLYGON = (1 << 8) | 0;
- static final int CONCAVE_POLYGON = (1 << 8) | 1;
- static final int CONVEX_POLYGON = (1 << 8) | 2;
+ //static final int CONCAVE_POLYGON = (1 << 8) | 1;
+ //static final int CONVEX_POLYGON = (1 << 8) | 2;
// shape modes
@@ -195,15 +196,14 @@ public interface PConstants {
// stroke modes
- static final int SQUARE = 1 << 0;
- static final int ROUND = 1 << 1;
- static final int PROJECTED = 1 << 2;
- static final int CAP_MASK = SQUARE | ROUND | PROJECTED;
-
- static final int MITERED = 1 << 3;
+ static final int SQUARE = 1 << 0;
+ static final int ROUND = 1 << 1;
+ static final int PROJECT = 1 << 2;
+ //static final int CAP_MASK = SQUARE | ROUND | PROJECT;
+ static final int MITER = 1 << 3;
//static final int ROUND = 1 << 4;
- static final int BEVELED = 1 << 5;
- static final int JOIN_MASK = MITERED | ROUND | BEVELED;
+ static final int BEVEL = 1 << 5;
+ //static final int JOIN_MASK = MITERED | ROUND | BEVELED;
// lighting
@@ -216,8 +216,8 @@ public interface PConstants {
// net
- static final int CLIENT = 0;
- static final int SERVER = 1;
+ //static final int CLIENT = 0;
+ //static final int SERVER = 1;
// key constants
diff --git a/core/PGraphics.java b/core/PGraphics.java
index 00b69f7f0..2ffc1dfbd 100644
--- a/core/PGraphics.java
+++ b/core/PGraphics.java
@@ -189,6 +189,14 @@ public class PGraphics extends PImage implements PConstants {
{ -3, 3, 0, 0},
{ 1, 0, 0, 0}
};
+
+ protected PMatrix bezierBasis =
+ new PMatrix(RADIANS,
+ -1, 3, -3, 1,
+ 3, -6, 3, 0,
+ -3, 3, 0, 0,
+ 1, 0, 0, 0);
+
protected float bezier_forward[][]; // = new float[4][4];
protected float bezier_draw[][]; // = new float[4][4];
@@ -202,6 +210,9 @@ public class PGraphics extends PImage implements PConstants {
protected float curve_forward[][]; // = new float[4][4];
protected float curve_draw[][];
+ protected PMatrix bezierBasisInverse;
+ protected PMatrix curveToBezierMatrix;
+
// ........................................................
// spline vertices
@@ -369,7 +380,11 @@ public class PGraphics extends PImage implements PConstants {
colorMode(RGB, TFF);
fill(TFF);
stroke(0);
+
strokeWeight(ONE);
+ strokeCap(SQUARE);
+ strokeJoin(MITER);
+
background(204);
// init shape stuff
@@ -588,8 +603,8 @@ public class PGraphics extends PImage implements PConstants {
break;
case POLYGON:
- case CONCAVE_POLYGON:
- case CONVEX_POLYGON:
+ //case CONCAVE_POLYGON:
+ //case CONVEX_POLYGON:
if (vertexCount == 1) {
path = new Path();
path.moveTo(x, y);
@@ -619,7 +634,15 @@ public class PGraphics extends PImage implements PConstants {
}
- public void bezierVertex(float x, float y) {
+ public void bezierVertex(float x1, float y1,
+ float x2, float y2,
+ float x3, float y3) {
+ // if there hasn't yet been a call to vertex(), throw an error
+
+ // otherwise, draw a bezier segment to this point
+ }
+
+ protected void bezier_vertex(float x, float y) {
vertexCount = 0;
if (splineVertices == null) {
@@ -640,9 +663,8 @@ public class PGraphics extends PImage implements PConstants {
switch (shape) {
case LINE_LOOP:
+ case LINE_STRIP:
case POLYGON:
- case CONCAVE_POLYGON:
- case CONVEX_POLYGON:
if (splineVertexCount == 1) {
path.moveTo(x, y);
@@ -662,10 +684,9 @@ public class PGraphics extends PImage implements PConstants {
}
- /**
- * See notes with the bezier() function.
- */
- public void bezierVertex(float x, float y, float z) {
+ public void bezierVertex(float x1, float y1, float z1,
+ float x2, float y2, float z2,
+ float x3, float y3, float z3) {
throw new RuntimeException("bezierVertex(x, y, z) can only be used with " +
"depth(), use bezierVertex(x, y) instead.");
}
@@ -703,8 +724,8 @@ public class PGraphics extends PImage implements PConstants {
break;
case POLYGON:
- case CONCAVE_POLYGON:
- case CONVEX_POLYGON:
+ //case CONCAVE_POLYGON:
+ //case CONVEX_POLYGON:
path.closePath();
draw_shape(path);
break;
@@ -924,14 +945,13 @@ public class PGraphics extends PImage implements PConstants {
if (angleMode == DEGREES) {
start = start * DEG_TO_RAD;
stop = stop * DEG_TO_RAD;
-
- // before running a while loop like this,
- // make sure it will exit at some point.
- if (Float.isInfinite(start) || Float.isInfinite(stop)) return;
- while (stop < start) stop += TWO_PI;
}
+ // before running a while loop like this,
+ // make sure it will exit at some point.
+ if (Float.isInfinite(start) || Float.isInfinite(stop)) return;
+ while (stop < start) stop += TWO_PI;
- arcImpl(start, stop, x, y, w, h);
+ arcImpl(x, y, w, h, start, stop);
}
@@ -979,8 +999,8 @@ public class PGraphics extends PImage implements PConstants {
* b and c are the control points. this can be done once with the
* x coordinates and a second time with the y coordinates to get
* the location of a bezier curve at t.
- *
- * for instance, to convert the following example:
+ * For instance, to convert the following example:
+ *
+ * endShape();
*/
public float bezierPoint(float a, float b, float c, float d, float t) {
float t1 = 1.0f - t;
@@ -1030,51 +1050,28 @@ public class PGraphics extends PImage implements PConstants {
* Draw a bezier curve. The first and last points are
* the on-curve points. The middle two are the 'control' points,
* or 'handles' in an application like Illustrator.
- *
+ *
* stroke(255, 102, 0);
* line(85, 20, 10, 10);
* line(90, 90, 15, 80);
@@ -994,11 +1014,11 @@ public class PGraphics extends PImage implements PConstants {
* beginShape(LINE_STRIP);
* for (int i = 0; i <= 10; i++) {
* float t = i / 10.0f;
- * float x = bezier(85, 10, 90, 15, t);
- * float y = bezier(20, 10, 90, 80, t);
+ * float x = bezierPoint(85, 10, 90, 15, t);
+ * float y = bezierPoint(20, 10, 90, 80, t);
* vertex(x, y);
* }
- * endShape();
* Identical to typing: - * beginShape(); - * bezierVertex(x1, y1); - * bezierVertex(x2, y2); - * bezierVertex(x3, y3); - * bezierVertex(x4, y4); - * endShape(); + *
beginShape(); + * vertex(x1, y1); + * bezierVertex(x2, y2, x3, y3, x4, y4); + * endShape();* * In Postscript-speak, this would be: - * moveto(x1, y1); - * curveto(x2, y2, x3, y3, x4, y4); + *
moveto(x1, y1); + * curveto(x2, y2, x3, y3, x4, y4);* If you were to try and continue that curve like so: - * curveto(x5, y5, x6, y6, x7, y7); - * This would be done in bagel by adding these statements: - * curveVertex(x4, y4); - * curveVertex(x5, y5); - * curveVertex(x6, y6); - * curveVertex(x7, y7); - * Note that x4/y4 are being pulled from the previous - * curveto and used again. - * - * The solution here may be a bit more verbose than Postscript, - * but in general, decisions opted for maximum flexibility, - * since these beginShape() commands are intended as a bit lower-level. - * Rather than having many types of curveto (curve to corner, - * and several others described in the Postscript and Illustrator specs) - * let someone else implement a nice moveto/lineto/curveto library on top. - * In fact, it's tempting that we may put one in there ourselves. - * - * Another method for bezier (though not implemented this way) - * 1. first start with a call to vertex() - * 2. every three calls to bezierVertex produce a new segment - * This option seemed no good because of the confusion of mixing - * vertex and bezierVertex calls. + *
curveto(x5, y5, x6, y6, x7, y7);+ * This would be done in processing by adding these statements: + *
bezierVertex(x5, y5, x6, y6, x7, y7)*/ public void bezier(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { beginShape(LINE_STRIP); - bezierVertex(x1, y1); - bezierVertex(x2, y2); - bezierVertex(x3, y3); - bezierVertex(x4, y4); + vertex(x1, y1); + bezierVertex(x2, y2, x3, y3, x4, y4); endShape(); } @@ -1131,7 +1128,7 @@ public class PGraphics extends PImage implements PConstants { * curve, and setting the s parameter, which defines how tightly * the curve fits to each vertex. Catmull-Rom curves are actually * a subset of this curve type where the s is set to zero. - * + *
* (This function is not optimized, since it's not expected to * be called all that often. there are many juicy and obvious * opimizations in here, but it's probably better to keep the @@ -1164,6 +1161,18 @@ public class PGraphics extends PImage implements PConstants { } setup_spline_forward(segments, curve_forward); + if (bezierBasisInverse == null) { + bezierBasisInverse = new PMatrix(bezierBasis).invert(); + } + + // hack here to get PGraphics2 working + curveToBezierMatrix = new PMatrix(RADIANS, + c[0][0], c[0][1], c[0][2], c[0][3], + c[1][0], c[1][1], c[1][2], c[1][3], + c[2][0], c[2][1], c[2][2], c[2][3], + c[3][0], c[3][1], c[3][2], c[3][3]); + curveToBezierMatrix.preApplyMatrix(bezierBasisInverse); + // multiply the basis and forward diff matrices together // saves much time since this needn't be done for each curve mult_spline_matrix(curve_forward, curve_basis, curve_draw, 4); @@ -1199,18 +1208,19 @@ public class PGraphics extends PImage implements PConstants { /** * Draws a segment of Catmull-Rom curve. - * - * Identical to typing out: + *
+ * As of 0070, this function no longer doubles the first and + * last points. The curves are a bit more boring, but it's more + * mathematically correct, and properly mirrored in curvePoint(). + *
+ * Identical to typing out:
* beginShape();
* curveVertex(x1, y1);
* curveVertex(x2, y2);
* curveVertex(x3, y3);
* curveVertex(x4, y4);
* endShape();
- *
- * As of 0070, this function no longer doubles the first and
- * last points. The curves are a bit more boring, but it's more
- * mathematically correct, and properly mirrored in curvePoint().
+ *
*/
public void curve(float x1, float y1,
float x2, float y2,
@@ -2286,16 +2296,10 @@ public class PGraphics extends PImage implements PConstants {
}
- // if high bit isn't set, then it's not a #ffcc00 style web color
- // so redirect to the float version, b/c they want a gray.
- // only danger is that someone would try to set the color to a
- // zero alpha.. which would be kooky but not unlikely
- // (i.e. if it were in a loop) so in addition to checking the high
- // bit, check to see if the value is at least just below the
- // colorModeX (i.e. 0..255). can't just check the latter since
- // if the high bit is > 0x80 then the int value for rgb will be
- // negative. yay for no unsigned types in java!
-
+ /**
+ * Set the tint to either a grayscale or ARGB value. See notes
+ * attached to the fill() function.
+ */
public void tint(int rgb) {
if (((rgb & 0xff000000) == 0) && (rgb <= colorModeX)) {
tint((float) rgb);
@@ -2338,6 +2342,26 @@ public class PGraphics extends PImage implements PConstants {
}
+ /**
+ * Set the fill to either a grayscale value or an ARGB int.
+ * + * The problem with this code is that it has to detect between + * these two situations automatically. This is done by checking + * to see if the high bits (the alpha for 0xAA000000) is set, + * and if not, whether the color value that follows is less than + * colorModeX (the first param passed to colorMode). + *
+ * This auto-detect would break in the following situation: + *
size(256, 256);
+ * for (int i = 0; i < 256; i++) {
+ * color c = color(0, 0, 0, i);
+ * stroke(c);
+ * line(i, 0, i, 256);
+ * }
+ * ...on the first time through the loop, where (i == 0),
+ * since the color itself is zero (black) then it would appear
+ * indistinguishable from someone having written fill(0).
+ */
public void fill(int rgb) {
if (((rgb & 0xff000000) == 0) && (rgb <= colorModeX)) { // see above
fill((float) rgb);
@@ -2396,6 +2420,10 @@ public class PGraphics extends PImage implements PConstants {
}
+ /**
+ * Set the tint to either a grayscale or ARGB value. See notes
+ * attached to the fill() function.
+ */
public void stroke(int rgb) {
if (((rgb & 0xff000000) == 0) && (rgb <= colorModeX)) { // see above
stroke((float) rgb);
@@ -2441,7 +2469,7 @@ public class PGraphics extends PImage implements PConstants {
* before drawing.
*/
public void background(int rgb) {
- if (((rgb & 0xff000000) == 0) && (rgb <= colorModeX)) { // see above
+ if (((rgb & 0xff000000) == 0) && (rgb <= colorModeX)) {
background((float) rgb);
} else {
@@ -2467,12 +2495,12 @@ public class PGraphics extends PImage implements PConstants {
/**
- * Takes an RGB or RGBA image and sets it as the background.
- *
+ * Takes an RGB or ARGB image and sets it as the background.
+ * * Note that even if the image is set as RGB, the high 8 bits of * each pixel must be set (0xFF000000), because the image data will * be copied directly to the screen. - * + *
* Also clears out the zbuffer and stencil buffer if they exist. */ public void background(PImage image) { @@ -2490,13 +2518,15 @@ public class PGraphics extends PImage implements PConstants { /** - * Clears pixel buffer. Also clears the stencil and zbuffer + * Clears pixel buffer. Subclasses (PGraphics3) will also clear the + * stencil and zbuffer * if they exist. Their existence is more accurate than using 'depth' * to test whether to clear them, because if they're non-null, * it means that depth() has been called somewhere in the program, * even if noDepth() was called before draw() exited. */ - public void clear() { + //public void clear() { + protected void clear() { for (int i = 0; i < pixelCount; i++) { pixels[i] = backgroundColor; } diff --git a/core/PGraphics2.java b/core/PGraphics2.java index 0f2848f98..a347c4a02 100644 --- a/core/PGraphics2.java +++ b/core/PGraphics2.java @@ -159,7 +159,6 @@ public class PGraphics2 extends PGraphics { case LINE_STRIP: case LINE_LOOP: if (gpath == null) { - //if (vertexCount == 1) { gpath = new GeneralPath(); gpath.moveTo(x, y); } else { @@ -273,8 +272,8 @@ public class PGraphics2 extends PGraphics { break; case POLYGON: - case CONCAVE_POLYGON: - case CONVEX_POLYGON: + //case CONCAVE_POLYGON: + //case CONVEX_POLYGON: //if (vertexCount == 1) { if (gpath == null) { //System.out.println("starting poly path " + x + " " + y); @@ -289,7 +288,39 @@ public class PGraphics2 extends PGraphics { } - public void bezierVertex(float x, float y) { + public void bezierVertex(float x1, float y1, + float x2, float y2, + float x3, float y3) { + //if (vertexCount == 0) { + if (gpath == null) { + throw new RuntimeException("Must call vertex() at least once " + + "before using bezierVertex()"); + } + + switch (shape) { + case LINE_LOOP: + case LINE_STRIP: + case POLYGON: + gpath.curveTo(x1, y1, x2, y2, x3, y3); + break; + + default: + throw new RuntimeException("bezierVertex() can only be used with " + + "LINE_STRIP, LINE_LOOP, or POLYGON"); + } + } + + + float curveX[] = new float[4]; + float curveY[] = new float[4]; + + public void curveVertex(float x, float y) { + if ((shape != LINE_LOOP) && (shape != LINE_STRIP) && (shape != POLYGON)) { + throw new RuntimeException("curveVertex() can only be used with " + + "LINE_LOOP, LINE_STRIP, and POLYGON shapes"); + } + + if (!curve_inited) curve_init(); vertexCount = 0; if (splineVertices == null) { @@ -304,35 +335,41 @@ public class PGraphics2 extends PGraphics { splineVertices[1], 0, VERTEX_FIELD_COUNT); splineVertexCount = 3; } + + // this new guy will be the fourth point (or higher), + // which means it's time to draw segments of the curve + if (splineVertexCount >= 3) { + curveX[0] = splineVertices[splineVertexCount-3][MX]; + curveY[0] = splineVertices[splineVertexCount-3][MY]; + + curveX[1] = splineVertices[splineVertexCount-2][MX]; + curveY[1] = splineVertices[splineVertexCount-2][MY]; + + curveX[2] = splineVertices[splineVertexCount-1][MX]; + curveY[2] = splineVertices[splineVertexCount-1][MY]; + + curveX[3] = x; + curveY[3] = y; + + curveToBezierMatrix.mult(curveX, curveX); + curveToBezierMatrix.mult(curveY, curveY); + + // since the paths are continuous, + // only the first point needs the actual moveto + if (gpath == null) { + gpath = new GeneralPath(); + gpath.moveTo(curveX[0], curveY[0]); + } + + gpath.curveTo(curveX[1], curveY[1], + curveX[2], curveY[2], + curveX[3], curveY[3]); + } + + // add the current point to the list splineVertices[splineVertexCount][MX] = x; splineVertices[splineVertexCount][MY] = y; splineVertexCount++; - - switch (shape) { - case LINE_LOOP: - case POLYGON: - case CONCAVE_POLYGON: - case CONVEX_POLYGON: - //if (splineVertexCount == 1) { - if (gpath == null) { - gpath = new GeneralPath(); - gpath.moveTo(x, y); - - } else if (splineVertexCount >= 4) { - gpath.curveTo(splineVertices[splineVertexCount-3][MX], - splineVertices[splineVertexCount-3][MY], - splineVertices[splineVertexCount-2][MX], - splineVertices[splineVertexCount-2][MY], - x, y); - } - break; - } - } - - - public void curveVertex(float x, float y) { - // TODO handle inverse matrix action - throw new RuntimeException("curveVertex() not yet implemented"); } @@ -361,8 +398,8 @@ public class PGraphics2 extends PGraphics { break; case POLYGON: - case CONCAVE_POLYGON: - case CONVEX_POLYGON: + //case CONCAVE_POLYGON: + //case CONVEX_POLYGON: //System.out.println("finishing polygon"); gpath.closePath(); draw_shape(gpath); @@ -377,14 +414,12 @@ public class PGraphics2 extends PGraphics { ////////////////////////////////////////////////////////////// - /* protected void fill_shape(Shape s) { if (fill) { - graphics.setColor(fillColorObject); - graphics.fill(s); + g2.setColor(fillColorObject); + g2.fill(s); } } - */ protected void stroke_shape(Shape s) { if (stroke) { @@ -507,16 +542,74 @@ public class PGraphics2 extends PGraphics { } - public void arcImpl(float x, float y, float w, float h, - float start, float stop) { - arc.setArc(x, y, w, h, start, stop-start, Arc2D.PIE); - draw_shape(arc); + protected void arcImpl(float x, float y, float w, float h, + float start, float stop) { + // 0 to 90 in java would be 0 to -90 for p5 renderer + // but that won't work, so -90 to 0? + + if (stop - start >= TWO_PI) { + start = 0; + stop = 360; + + } else { + start = -start * RAD_TO_DEG; + stop = -stop * RAD_TO_DEG; + + // ok to do this because already checked for NaN + //while (start < 0) start += 360; + //while (stop < 0) stop += 360; + while (start < 0) { + start += 360; + stop += 360; + } + /* + while (stop < 0) { + start += 360; + stop += 360; + } + */ + if (start > stop) { + float temp = start; + start = stop; + stop = temp; + } + } + float span = stop - start; + + /* + float span = stop - start; + start -= span; + + start *= RAD_TO_DEG; + span *= RAD_TO_DEG; + */ + + //start %= 360; + //System.out.println(RAD_TO_DEG*start + " " + RAD_TO_DEG*span); + //System.out.println(start + " " + span); + + // start is int proper place, but the stop is the wrong way + //float stop = start; + //float start = + + // stroke as Arc2D.OPEN, fill as Arc2D.PIE + if (fill) { + //System.out.println("filla"); + arc.setArc(x, y, w, h, start, span, Arc2D.PIE); + fill_shape(arc); + } + if (stroke) { + //System.out.println("strokey"); + arc.setArc(x, y, w, h, start, span, Arc2D.OPEN); + stroke_shape(arc); + } } ////////////////////////////////////////////////////////////// + /* public void bezier(float x1, float y1, float x2, float y2, float x3, float y3, @@ -528,6 +621,7 @@ public class PGraphics2 extends PGraphics { draw_shape(gp); } + */ public void bezierDetail(int detail) { @@ -539,6 +633,7 @@ public class PGraphics2 extends PGraphics { } + /* public void curveTightness(float tightness) { // TODO } @@ -549,8 +644,9 @@ public class PGraphics2 extends PGraphics { float x3, float y3, float x4, float y4) { // TODO need inverse catmull rom to bezier matrix - } + } + */ ////////////////////////////////////////////////////////////// @@ -621,10 +717,9 @@ public class PGraphics2 extends PGraphics { public ImageCache(PImage source) { this.source = source; - // if RGB, set the image type to RGB, - // otherwise it's ALPHA or ARGB, and use an ARGB bimage - int type = (source.format == RGB) ? - BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; + // even if RGB, set the image type to ARGB, because the + // image may have an alpha value for its tint(). + int type = BufferedImage.TYPE_INT_ARGB; image = new BufferedImage(source.width, source.height, type); } @@ -641,21 +736,42 @@ public class PGraphics2 extends PGraphics { int r2 = (tintColor >> 16) & 0xff; int g2 = (tintColor >> 8) & 0xff; int b2 = (tintColor) & 0xff; + //System.out.println("a2 is " + a2); // multiply each of the color components into tintedPixels - for (int i = 0; i < tintedPixels.length; i++) { - int argb1 = source.pixels[i]; - int a1 = (argb1 >> 24) & 0xff; - int r1 = (argb1 >> 16) & 0xff; - int g1 = (argb1 >> 8) & 0xff; - int b1 = (argb1) & 0xff; + // if straight RGB image, don't bother multiplying + // (also avoids problems if high bits not set) + if (source.format == RGB) { + int alpha = a2 << 24; - tintedPixels[i] = - (((a2 * a1) & 0xff00) << 16) | - (((r2 * r1) & 0xff00) << 8) | - ((g2 * g1) & 0xff00) | - (((b2 * b1) & 0xff00) >> 8); + for (int i = 0; i < tintedPixels.length; i++) { + int argb1 = source.pixels[i]; + int r1 = (argb1 >> 16) & 0xff; + int g1 = (argb1 >> 8) & 0xff; + int b1 = (argb1) & 0xff; + + tintedPixels[i] = alpha | + (((r2 * r1) & 0xff00) << 8) | + ((g2 * g1) & 0xff00) | + (((b2 * b1) & 0xff00) >> 8); + } + + } else { + for (int i = 0; i < tintedPixels.length; i++) { + int argb1 = source.pixels[i]; + int a1 = (argb1 >> 24) & 0xff; + int r1 = (argb1 >> 16) & 0xff; + int g1 = (argb1 >> 8) & 0xff; + int b1 = (argb1) & 0xff; + + tintedPixels[i] = + (((a2 * a1) & 0xff00) << 16) | + (((r2 * r1) & 0xff00) << 8) | + ((g2 * g1) & 0xff00) | + (((b2 * b1) & 0xff00) >> 8); + } } + tinted = true; tintedColor = tintColor; @@ -665,6 +781,7 @@ public class PGraphics2 extends PGraphics { } else { // no tint // just do a setRGB like before + // (and we'll just hope that the high bits are set) image.setRGB(0, 0, source.width, source.height, source.pixels, 0, source.width); } @@ -849,12 +966,12 @@ public class PGraphics2 extends PGraphics { int cap = BasicStroke.CAP_BUTT; if (strokeCap == ROUND) { cap = BasicStroke.CAP_ROUND; - } else if (strokeCap == PROJECTED) { + } else if (strokeCap == PROJECT) { cap = BasicStroke.CAP_SQUARE; } int join = BasicStroke.JOIN_BEVEL; - if (strokeJoin == MITERED) { + if (strokeJoin == MITER) { join = BasicStroke.JOIN_MITER; } else if (strokeJoin == ROUND) { join = BasicStroke.JOIN_ROUND; @@ -952,8 +1069,28 @@ public class PGraphics2 extends PGraphics { public PImage get(int x, int y, int w, int h) { + if (imageMode == CORNERS) { // if CORNER, do nothing + //x2 += x1; y2 += y1; + // w/h are x2/y2 in this case, bring em down to size + w = (w - x); + h = (h - x); + } + + if (x < 0) { + w += x; // clip off the left edge + x = 0; + } + if (y < 0) { + h += y; // clip off some of the height + y = 0; + } + + if (x + w > width) w = width - x; + if (y + h > height) h = height - y; + PImage output = new PImage(w, h); - ((BufferedImage) image).getRGB(x, y, w, h, output.pixels, 0, width); + // oops, the last parameter is the scan size of the *target* buffer + ((BufferedImage) image).getRGB(x, y, w, h, output.pixels, 0, w); return output; } diff --git a/core/PGraphics3.java b/core/PGraphics3.java index 3c175199b..543adba68 100644 --- a/core/PGraphics3.java +++ b/core/PGraphics3.java @@ -778,8 +778,8 @@ public class PGraphics3 extends PGraphics { break; case POLYGON: - case CONCAVE_POLYGON: - case CONVEX_POLYGON: + //case CONCAVE_POLYGON: + //case CONVEX_POLYGON: { // store index of first vertex int first = lineCount; @@ -853,8 +853,8 @@ public class PGraphics3 extends PGraphics { break; case POLYGON: - case CONCAVE_POLYGON: - case CONVEX_POLYGON: + //case CONCAVE_POLYGON: + //case CONVEX_POLYGON: { triangulate_polygon(); } @@ -1463,9 +1463,17 @@ public class PGraphics3 extends PGraphics { public void point(float x, float y, float z) { + /* beginShape(POINTS); vertex(x, y, z); endShape(); + */ + + // hacked workaround for carlos line bug + beginShape(LINES); + vertex(x, y, z); + vertex(x + EPSILON, y + EPSILON, z); + endShape(); } /* diff --git a/core/PImage.java b/core/PImage.java index 754fe761e..195c9ca07 100644 --- a/core/PImage.java +++ b/core/PImage.java @@ -2,11 +2,12 @@ /* PImage - storage class for pixel data - Part of the Processing project - http://Proce55ing.net + Part of the Processing project - http://processing.org Copyright (c) 2001-05 Ben Fry, Massachusetts Institute of Technology and Casey Reas, Interaction Design Institute Ivrea + Additional code contributions from toxi This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -33,7 +34,7 @@ import java.io.*; /** - * [fry 0407XX] + *
[fry 0407XX] * - get() on RGB images sets the high bits to opaque * - modification of naming for functions * - inclusion of Object.clone() @@ -66,7 +67,7 @@ import java.io.*; * image object as parameter. this is to provide an easy syntax for cases * where the main pixel buffer is the destination. as those methods are * overloaded in BApplet, users can call those functions directly without - * explicitly giving a reference to PGraphics. + * explicitly giving a reference to PGraphics.*/ public class PImage implements PConstants, Cloneable { @@ -299,14 +300,14 @@ public class PImage implements PConstants, Cloneable { * For subclasses where the pixels[] buffer isn't set by default, * this should copy all data into the pixels[] array */ - public void loadPixels() { + public void loadPixels() { // ignore } /** * Mark all pixels as needing update. */ - public void updatePixels() { + public void updatePixels() { // ignore updatePixels(0, 0, width, height); } @@ -315,7 +316,7 @@ public class PImage implements PConstants, Cloneable { * Note that when using imageMode(CORNERS), * the x2 and y2 positions are non-inclusive. */ - public void updatePixels(int x1, int y1, int x2, int y2) { + public void updatePixels(int x1, int y1, int x2, int y2) { // ignore //if (!modified) { // could just set directly, but.. //} @@ -382,15 +383,16 @@ public class PImage implements PConstants, Cloneable { // w/h are x2/y2 in this case, bring em down to size w = (w - x); h = (h - x); - - //} else if (imageMode == CENTER) { - // w/h are the proper w/h, but x/y need to be moved - //x -= w/2; - //y -= h/2; } - if (x < 0) x = 0; - if (y < 0) y = 0; + if (x < 0) { + w += x; // clip off the left edge + x = 0; + } + if (y < 0) { + h += y; // clip off some of the height + y = 0; + } if (x + w > width) w = width - x; if (y + h > height) h = height - y; @@ -410,10 +412,8 @@ public class PImage implements PConstants, Cloneable { /** - * Convenience method to avoid an extra cast, - * and the exception handling. + * Returns a copy of this PImage. Equivalent to get(0, 0, width, height). */ - /* public PImage get() { try { return (PImage) clone(); @@ -421,7 +421,6 @@ public class PImage implements PConstants, Cloneable { return null; } } - */ public void set(int x, int y, int c) { @@ -487,31 +486,26 @@ public class PImage implements PConstants, Cloneable { /** - * Options to filter an image in place. - * RGB set all the high bits in the image to opaque - * and sets the format to RGB - * FIND_EDGES (no params) .. high pass filter - * BLUR (no params) - * GAUSSIAN_BLUR (one param) - * BLACK_WHITE? (param for midpoint) - * GRAYSCALE - * POSTERIZE (int num of levels) + * Method to apply a variety of basic filters to this image. + *
+ *
+ *