diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index d32f26192..51dc0860e 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -9908,6 +9908,18 @@ public class PApplet extends Applet } + public void clip(float a, float b, float c, float d) { + if (recorder != null) recorder.clip(a, b, c, d); + g.clip(a, b, c, d); + } + + + public void noClip() { + if (recorder != null) recorder.noClip(); + g.noClip(); + } + + public void bezierVertex(float x2, float y2, float x3, float y3, float x4, float y4) { diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index b26a7f604..dd419c659 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -1405,7 +1405,14 @@ public class PGraphics extends PImage implements PConstants { } + public void clip(float a, float b, float c, float d) { + showMissingWarning("clip"); + } + public void noClip() { + showMissingWarning("noClip"); + } + ////////////////////////////////////////////////////////////// // CURVE/BEZIER VERTEX HANDLING diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index 939c7307b..24bb4fe62 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -466,7 +466,9 @@ public class PGraphicsOpenGL extends PGraphics { static protected int pointAttribsID; protected boolean drawing2D; - protected PImage textureImage0; + protected PImage textureImage0; + + protected boolean clip = false; static public float FLOAT_EPS = Float.MIN_VALUE; // Calculation of the Machine Epsilon for float precision. From: @@ -657,7 +659,7 @@ public class PGraphicsOpenGL extends PGraphics { int idx = temp[0]; if (glTextureObjects.containsKey(idx)) { - System.err.println("Adding same texture twice"); + showWarning("Adding same texture twice"); } else { glTextureObjects.put(idx, false); } @@ -670,7 +672,7 @@ public class PGraphicsOpenGL extends PGraphics { if (glTextureObjects.containsKey(idx)) { glTextureObjects.put(idx, true); } else { - System.err.println("Trying to finalize non-existing texture"); + showWarning("Trying to finalize non-existing texture"); } } @@ -701,7 +703,7 @@ public class PGraphicsOpenGL extends PGraphics { int idx = temp[0]; if (glVertexBuffers.containsKey(idx)) { - System.err.println("Adding same VBO twice"); + showWarning("Adding same VBO twice"); } else { glVertexBuffers.put(idx, false); } @@ -714,7 +716,7 @@ public class PGraphicsOpenGL extends PGraphics { if (glVertexBuffers.containsKey(idx)) { glVertexBuffers.put(idx, true); } else { - System.err.println("Trying to finalize non-existing VBO"); + showWarning("Trying to finalize non-existing VBO"); } } @@ -745,7 +747,7 @@ public class PGraphicsOpenGL extends PGraphics { int idx = temp[0]; if (glFrameBuffers.containsKey(idx)) { - System.err.println("Adding same FBO twice"); + showWarning("Adding same FBO twice"); } else { glFrameBuffers.put(idx, false); } @@ -758,7 +760,7 @@ public class PGraphicsOpenGL extends PGraphics { if (glFrameBuffers.containsKey(idx)) { glFrameBuffers.put(idx, true); } else { - System.err.println("Trying to finalize non-existing FBO"); + showWarning("Trying to finalize non-existing FBO"); } } @@ -789,7 +791,7 @@ public class PGraphicsOpenGL extends PGraphics { int idx = temp[0]; if (glRenderBuffers.containsKey(idx)) { - System.err.println("Adding same renderbuffer twice"); + showWarning("Adding same renderbuffer twice"); } else { glRenderBuffers.put(idx, false); } @@ -802,7 +804,7 @@ public class PGraphicsOpenGL extends PGraphics { if (glRenderBuffers.containsKey(idx)) { glRenderBuffers.put(idx, true); } else { - System.err.println("Trying to finalize non-existing renderbuffer"); + showWarning("Trying to finalize non-existing renderbuffer"); } } @@ -833,7 +835,7 @@ public class PGraphicsOpenGL extends PGraphics { int idx = gl2x.glCreateProgram(); if (glslPrograms.containsKey(idx)) { - System.err.println("Adding same glsl program twice"); + showWarning("Adding same glsl program twice"); } else { glslPrograms.put(idx, false); } @@ -846,7 +848,7 @@ public class PGraphicsOpenGL extends PGraphics { if (glslPrograms.containsKey(idx)) { glslPrograms.put(idx, true); } else { - System.err.println("Trying to finalize non-existing glsl program"); + showWarning("Trying to finalize non-existing glsl program"); } } @@ -874,7 +876,7 @@ public class PGraphicsOpenGL extends PGraphics { int idx = gl2x.glCreateShader(GL2.GL_VERTEX_SHADER); if (glslVertexShaders.containsKey(idx)) { - System.err.println("Adding same glsl vertex shader twice"); + showWarning("Adding same glsl vertex shader twice"); } else { glslVertexShaders.put(idx, false); } @@ -887,7 +889,7 @@ public class PGraphicsOpenGL extends PGraphics { if (glslVertexShaders.containsKey(idx)) { glslVertexShaders.put(idx, true); } else { - System.err.println("Trying to finalize non-existing glsl vertex shader"); + showWarning("Trying to finalize non-existing glsl vertex shader"); } } @@ -916,7 +918,7 @@ public class PGraphicsOpenGL extends PGraphics { int idx = gl2x.glCreateShader(GL2.GL_FRAGMENT_SHADER); if (glslFragmentShaders.containsKey(idx)) { - System.err.println("Adding same glsl fragment shader twice"); + showWarning("Adding same glsl fragment shader twice"); } else { glslFragmentShaders.put(idx, false); } @@ -929,7 +931,7 @@ public class PGraphicsOpenGL extends PGraphics { if (glslFragmentShaders.containsKey(idx)) { glslFragmentShaders.put(idx, true); } else { - System.err.println("Trying to finalize non-existing glsl fragment shader"); + showWarning("Trying to finalize non-existing glsl fragment shader"); } } @@ -1093,7 +1095,7 @@ public class PGraphicsOpenGL extends PGraphics { public void beginDraw() { if (drawing) { - System.err.println("P3D: Already called beginDraw()."); + showWarning("P3D: Already called beginDraw()."); return; } @@ -1242,7 +1244,7 @@ public class PGraphicsOpenGL extends PGraphics { } if (!drawing) { - System.err.println("P3D: Cannot call endDraw() before beginDraw()."); + showWarning("P3D: Cannot call endDraw() before beginDraw()."); return; } @@ -1639,10 +1641,6 @@ public class PGraphicsOpenGL extends PGraphics { } else if (shape == POLYGON) { tessellator.tessellatePolygon(false, mode == CLOSE); } - - if (mode == TEXT) { - - } if (flushMode == FLUSH_AFTER_SHAPE || (flushMode == FLUSH_WHEN_FULL && tess.isFull()) || @@ -1765,6 +1763,60 @@ public class PGraphicsOpenGL extends PGraphics { } + public void clip(float a, float b, float c, float d) { + if (imageMode == CORNER) { + if (c < 0) { // reset a negative width + a += c; c = -c; + } + if (d < 0) { // reset a negative height + b += d; d = -d; + } + + clipImpl(a, b, a + c, b + d); + + } else if (imageMode == CORNERS) { + if (c < a) { // reverse because x2 < x1 + float temp = a; a = c; c = temp; + } + if (d < b) { // reverse because y2 < y1 + float temp = b; b = d; d = temp; + } + + clipImpl(a, b, c, d); + + } else if (imageMode == CENTER) { + // c and d are width/height + if (c < 0) c = -c; + if (d < 0) d = -d; + float x1 = a - c/2; + float y1 = b - d/2; + + clipImpl(x1, y1, x1 + c, y1 + d); + } + } + + + protected void clipImpl(float x1, float y1, float x2, float y2) { + flush(); + gl.glEnable(GL.GL_SCISSOR_TEST); + + float h = y2 - y1; + gl.glScissor((int)x1, (int)(height - y1 - h), (int)(x2 - x1), (int)h); + + clip = true; + } + + + public void noClip() { + if (clip) { + flush(); + gl.glDisable(GL.GL_SCISSOR_TEST); + + clip = false; + } + } + + ////////////////////////////////////////////////////////////// // RENDERING @@ -2922,10 +2974,6 @@ public class PGraphicsOpenGL extends PGraphics { protected void textCharModelImpl(PFontTexture.TextureInfo info, float x0, float y0, float x1, float y1) { -// if (textTex.currentTex != info.texIndex) { -// textTex.setTexture(info.texIndex); -// } - PImage tex = textTex.getTexture(info.texIndex); beginShape(QUADS); @@ -2934,7 +2982,7 @@ public class PGraphicsOpenGL extends PGraphics { vertex(x1, y0, info.u1, info.v0); vertex(x1, y1, info.u1, info.v1); vertex(x0, y1, info.u0, info.v1); - endShape(TEXT); + endShape(); } diff --git a/java/libraries/opengl/src/processing/opengl/PShader.java b/java/libraries/opengl/src/processing/opengl/PShader.java index 7130da682..eef38097a 100644 --- a/java/libraries/opengl/src/processing/opengl/PShader.java +++ b/java/libraries/opengl/src/processing/opengl/PShader.java @@ -118,7 +118,7 @@ public class PShader { shaderSource = PApplet.join(PApplet.loadStrings(url.openStream()), "\n"); attachVertexShader(shaderSource, url.getFile()); } catch (IOException e) { - System.err.println("Cannot load file " + url.getFile()); + PGraphics.showException("Cannot load shader " + url.getFile()); } } @@ -147,7 +147,7 @@ public class PShader { shaderSource = PApplet.join(PApplet.loadStrings(url.openStream()), "\n"); attachFragmentShader(shaderSource, url.getFile()); } catch (IOException e) { - System.err.println("Cannot load file " + url.getFile()); + PGraphics.showException("Cannot load shader " + url.getFile()); } } @@ -173,7 +173,7 @@ public class PShader { */ public void start() { if (!initialized) { - System.err.println("This shader is not properly initialized. Call the setup() method first"); + PGraphics.showWarning("This shader is not properly initialized. Call the setup() method first"); } // TODO: diff --git a/java/libraries/opengl/src/processing/opengl/PShape3D.java b/java/libraries/opengl/src/processing/opengl/PShape3D.java index 6511832e6..59924ae84 100644 --- a/java/libraries/opengl/src/processing/opengl/PShape3D.java +++ b/java/libraries/opengl/src/processing/opengl/PShape3D.java @@ -291,7 +291,7 @@ public class PShape3D extends PShape { protected void vertexImpl(float x, float y, float z, float u, float v, int code) { if (family != GEOMETRY && family != PATH) { - System.err.println("Cannot add vertices to GROUP of PRIMITIVE shape"); + PGraphics.showWarning("Cannot add vertices to GROUP of PRIMITIVE shape"); return; } @@ -1249,7 +1249,7 @@ public class PShape3D extends PShape { modified = true; child.modified = true; } else { - System.err.println("Cannot add child shape to non-group shape."); + PGraphics.showWarning("Cannot add child shape to non-group shape."); } } diff --git a/java/libraries/opengl/src/processing/opengl/PTexture.java b/java/libraries/opengl/src/processing/opengl/PTexture.java index 3b2f7d656..a13f003ed 100644 --- a/java/libraries/opengl/src/processing/opengl/PTexture.java +++ b/java/libraries/opengl/src/processing/opengl/PTexture.java @@ -27,6 +27,7 @@ import javax.media.opengl.GL2; import java.nio.*; import processing.core.PApplet; import processing.core.PConstants; +import processing.core.PGraphics; import processing.core.PImage; /** @@ -256,11 +257,11 @@ public class PTexture implements PConstants { public void set(int[] pixels, int x, int y, int w, int h, int format) { if (pixels == null) { - System.err.println("PTexture: null pixels array"); + PGraphics.showWarning("The pixels array is null."); return; } if (pixels.length != w * h) { - System.err.println("PTexture: wrong length of pixels array"); + PGraphics.showWarning("The pixels array has the wrong length. It should be " + w * h); return; } diff --git a/java/libraries/video/src/processing/video/Capture.java b/java/libraries/video/src/processing/video/Capture.java index ea706ca79..d88b6a0a9 100644 --- a/java/libraries/video/src/processing/video/Capture.java +++ b/java/libraries/video/src/processing/video/Capture.java @@ -194,7 +194,7 @@ public class Capture extends PImage implements PConstants { gpipeline.stop(); } } catch (IllegalStateException e) { - System.err.println("error when deleting player, maybe some native resource is already disposed"); + PGraphics.showWarning("Error when deleting player, maybe some native resource is already disposed"); } catch (Exception e) { e.printStackTrace(); } @@ -441,7 +441,7 @@ public class Capture extends PImage implements PConstants { res[i] = devices.get(i); } } else { - System.err.println("The capture plugin doesn't support device query!"); + PGraphics.showWarning("The capture plugin doesn't support device query!"); res = new String[0]; } } @@ -729,11 +729,11 @@ public class Capture extends PImage implements PConstants { if (!fps.equals("")) { fpsStr = ", " + fps + "fps"; } - System.err.println("The requested resolution of " + reqWidth + "x" + reqHeight + fpsStr + " is not supported by selected the capture device."); - System.err.println("Use one of the following resolutions instead:"); + PGraphics.showWarning("The requested resolution of " + reqWidth + "x" + reqHeight + fpsStr + " is not supported by selected the capture device."); + PGraphics.showWarning("Use one of the following resolutions instead:"); for (int i = 0; i < resolutions.size(); i++) { Resolution res = resolutions.get(i); - System.err.println(res.toString()); + PGraphics.showWarning(res.toString()); } } } diff --git a/java/libraries/video/src/processing/video/Movie.java b/java/libraries/video/src/processing/video/Movie.java index b001efffb..2e977e7e0 100644 --- a/java/libraries/video/src/processing/video/Movie.java +++ b/java/libraries/video/src/processing/video/Movie.java @@ -108,7 +108,7 @@ public class Movie extends PImage implements PConstants { gplayer.stop(); } } catch (IllegalStateException e) { - System.err.println("error when deleting player, maybe some native resource is already disposed"); + PGraphics.showWarning("error when deleting player, maybe some native resource is already disposed"); } catch (Exception e) { e.printStackTrace(); } @@ -230,7 +230,7 @@ public class Movie extends PImage implements PConstants { SeekType.SET, start, SeekType.SET, stop); if (!res) { - System.err.println("Seek operation failed."); + PGraphics.showWarning("Seek operation failed."); } if (playing) { @@ -327,7 +327,7 @@ public class Movie extends PImage implements PConstants { SeekType.SET, pos, SeekType.NONE, -1); if (!res) { - System.err.println("Seek operation failed."); + PGraphics.showWarning("Seek operation failed."); } // getState() will wait until any async state change