From b52563aed22fdb9da8dc097b2c549612d5465bde Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 16 Feb 2013 19:32:01 -0500 Subject: [PATCH 1/5] added mode to primitive PShape of type ARC --- core/src/processing/opengl/PGraphics2D.java | 2 +- core/src/processing/opengl/PGraphics3D.java | 2 +- core/src/processing/opengl/PShapeOpenGL.java | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/processing/opengl/PGraphics2D.java b/core/src/processing/opengl/PGraphics2D.java index 7b5bf9f0a..21a516554 100644 --- a/core/src/processing/opengl/PGraphics2D.java +++ b/core/src/processing/opengl/PGraphics2D.java @@ -389,7 +389,7 @@ public class PGraphics2D extends PGraphicsOpenGL { shape = new PShapeOpenGL(parent, PShape.PRIMITIVE); shape.setKind(ELLIPSE); } else if (kind == ARC) { - if (len != 6) { + if (len != 6 && len != 7) { showWarning("Wrong number of parameters"); return null; } diff --git a/core/src/processing/opengl/PGraphics3D.java b/core/src/processing/opengl/PGraphics3D.java index 1e0e4f12c..0880651cc 100644 --- a/core/src/processing/opengl/PGraphics3D.java +++ b/core/src/processing/opengl/PGraphics3D.java @@ -260,7 +260,7 @@ public class PGraphics3D extends PGraphicsOpenGL { shape = new PShapeOpenGL(parent, PShape.PRIMITIVE); shape.setKind(ELLIPSE); } else if (kind == ARC) { - if (len != 6) { + if (len != 6 && len != 7) { showWarning("Wrong number of parameters"); return null; } diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 4de45355d..2c22e7149 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -3416,7 +3416,7 @@ public class PShapeOpenGL extends PShape { d = params[3]; } - ellipseMode = CORNER; +// ellipseMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); @@ -3428,20 +3428,24 @@ public class PShapeOpenGL extends PShape { protected void tessellateArc() { float a = 0, b = 0, c = 0, d = 0; float start = 0, stop = 0; - if (params.length == 6) { + int mode = 0; + if (params.length == 6 || params.length == 7) { a = params[0]; b = params[1]; c = params[2]; d = params[3]; start = params[4]; stop = params[5]; + if (params.length == 7) { + mode = (int)(params[6]); + } } - ellipseMode = CORNER; +// ellipseMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); - inGeo.addArc(a, b, c, d, start, stop, fill, stroke, ellipseMode); + inGeo.addArc(a, b, c, d, start, stop, fill, stroke, mode); tessellator.tessellateTriangleFan(); } From 5c01de03ac302a44242e37f579e7b833d77f72cc Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 17 Feb 2013 09:54:56 -0500 Subject: [PATCH 2/5] fixed issue with transparency and PShader filters --- core/src/processing/opengl/PGL.java | 38 +++++++++++++------ .../processing/opengl/PGraphicsOpenGL.java | 7 +++- core/src/processing/opengl/Texture.java | 4 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 004a65b94..7bb8e7929 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -61,8 +61,6 @@ import processing.event.MouseEvent; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.event.InputEvent; -import com.jogamp.newt.event.WindowEvent; -import com.jogamp.newt.event.WindowUpdateEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.FBObject; import com.jogamp.opengl.util.AnimatorBase; @@ -630,6 +628,7 @@ public class PGL { canvasAWT = new GLCanvas(caps); canvasAWT.setBounds(0, 0, pg.width, pg.height); canvasAWT.setBackground(new Color(pg.backgroundColor, true)); + canvasAWT.setFocusable(true); pg.parent.setLayout(new BorderLayout()); pg.parent.add(canvasAWT, BorderLayout.CENTER); @@ -651,9 +650,7 @@ public class PGL { canvasNEWT = new NewtCanvasAWT(window); canvasNEWT.setBounds(0, 0, pg.width, pg.height); canvasNEWT.setBackground(new Color(pg.backgroundColor, true)); - - pg.parent.setLayout(new BorderLayout()); - pg.parent.add(canvasNEWT, BorderLayout.CENTER); + canvasNEWT.setFocusable(true); NEWTMouseListener mouseListener = new NEWTMouseListener(); window.addMouseListener(mouseListener); @@ -663,6 +660,9 @@ public class PGL { window.addWindowListener(winListener); canvasNEWT.addFocusListener(pg.parent); // So focus detection work. + pg.parent.setLayout(new BorderLayout()); + pg.parent.add(canvasNEWT, BorderLayout.CENTER); + capabilities = window.getChosenGLCapabilities(); canvas = canvasNEWT; canvasAWT = null; @@ -3237,6 +3237,7 @@ public class PGL { protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent, int peAction) { + if (!hasFocus) return; int modifiers = nativeEvent.getModifiers(); int peModifiers = modifiers & (InputEvent.SHIFT_MASK | @@ -3296,31 +3297,44 @@ public class PGL { pg.parent.postEvent(ke); } + boolean hasFocus = true; class NEWTWindowListener implements com.jogamp.newt.event.WindowListener { @Override - public void windowGainedFocus(WindowEvent arg0) { + public void windowGainedFocus(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("window gained focus"); pg.parent.focusGained(null); + hasFocus = true; } @Override - public void windowLostFocus(WindowEvent arg0) { + public void windowLostFocus(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("window lost focus"); pg.parent.focusLost(null); + hasFocus = false; } @Override - public void windowDestroyNotify(WindowEvent arg0) { } + public void windowDestroyNotify(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("destroy"); + } @Override - public void windowDestroyed(WindowEvent arg0) { } + public void windowDestroyed(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("destroyed"); + } @Override - public void windowMoved(WindowEvent arg0) { } + public void windowMoved(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("moved"); + } @Override - public void windowRepaint(WindowUpdateEvent arg0) { } + public void windowRepaint(com.jogamp.newt.event.WindowUpdateEvent arg0) { + PApplet.println("window repaint"); + } @Override - public void windowResized(WindowEvent arg0) { } + public void windowResized(com.jogamp.newt.event.WindowEvent arg0) { } } // NEWT mouse listener diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 75826ed70..8e26e9999 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -4971,8 +4971,8 @@ public class PGraphicsOpenGL extends PGraphics { // color buffer into it. @Override public void loadPixels() { - if (sized) { - // Something wrong going on with threading, sized can never be true if the + if (primarySurface && sized) { + // Something wrong going on with threading, sized can never be true if // all the steps in a resize happen inside the Animation thread. return; } @@ -5397,6 +5397,8 @@ public class PGraphicsOpenGL extends PGraphics { textureMode = NORMAL; boolean prevStroke = stroke; stroke = false; +// int prevBlendMode = blendMode; +// blendMode(REPLACE); PolyTexShader prevTexShader = polyTexShader; polyTexShader = (PolyTexShader) shader; beginShape(QUADS); @@ -5414,6 +5416,7 @@ public class PGraphicsOpenGL extends PGraphics { stroke = prevStroke; lights = prevLights; textureMode = prevTextureMode; +// blendMode(prevBlendMode); if (!hints[DISABLE_DEPTH_TEST]) { pgl.enable(PGL.DEPTH_TEST); diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index f4eacf60a..32d9a648f 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -328,7 +328,6 @@ public class Texture implements PConstants { public void set(int[] pixels, int x, int y, int w, int h, int format) { if (pixels == null) { - pixels = null; PGraphics.showWarning("The pixels array is null."); return; } @@ -1283,6 +1282,9 @@ public class Texture implements PConstants { // FBO copy: pg.pushFramebuffer(); pg.setFramebuffer(tempFbo); + // Clear the color buffer to make sure that the alpha of the + pgl.clearColor(0, 0, 0, 0); + pgl.clear(PGL.COLOR_BUFFER_BIT); if (scale) { // Rendering tex into "this", and scaling the source rectangle // to cover the entire destination region. From 76f3f807ffe336531209672a66f3366f3b6cae73 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 17 Feb 2013 12:30:01 -0500 Subject: [PATCH 3/5] set default ambient color from fill --- core/src/processing/core/PShape.java | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index 2fa801684..5865a026f 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -653,6 +653,11 @@ public class PShape implements PConstants { } fill = false; + fillColor = 0x0; + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -665,6 +670,10 @@ public class PShape implements PConstants { fill = true; colorCalc(rgb); fillColor = calcColor; + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -677,6 +686,10 @@ public class PShape implements PConstants { fill = true; colorCalc(rgb, alpha); fillColor = calcColor; + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -689,6 +702,10 @@ public class PShape implements PConstants { fill = true; colorCalc(gray); fillColor = calcColor; + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -701,6 +718,15 @@ public class PShape implements PConstants { fill = true; colorCalc(gray, alpha); fillColor = calcColor; + + if (!setAmbient) { + ambient(fillColor); + setAmbient = false; + } + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -713,6 +739,10 @@ public class PShape implements PConstants { fill = true; colorCalc(x, y, z); fillColor = calcColor; + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -725,6 +755,10 @@ public class PShape implements PConstants { fill = true; colorCalc(x, y, z, a); fillColor = calcColor; + + if (!setAmbient) { + ambientColor = fillColor; + } } From e6989c6be051ee1a7aedc6fe1c33a275b81024a7 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 17 Feb 2013 14:35:15 -0500 Subject: [PATCH 4/5] Fixes #1498 --- core/src/processing/opengl/PGL.java | 2 +- core/src/processing/opengl/PShapeOpenGL.java | 28 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 7bb8e7929..fb3c1bc42 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -3237,7 +3237,7 @@ public class PGL { protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent, int peAction) { - if (!hasFocus) return; +// if (!hasFocus) return; int modifiers = nativeEvent.getModifiers(); int peModifiers = modifiers & (InputEvent.SHIFT_MASK | diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 2c22e7149..0fd9209e6 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -4436,8 +4436,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyVertices(int offset, int size) { tessGeo.updatePolyVerticesBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex); + tessGeo.polyVerticesBuffer.position(4 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, tessGeo.polyVerticesBuffer); + tessGeo.polyVerticesBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4445,8 +4447,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyColors(int offset, int size) { tessGeo.updatePolyColorsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor); + tessGeo.polyColorsBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, tessGeo.polyColorsBuffer); + tessGeo.polyColorsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4454,8 +4458,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyNormals(int offset, int size) { tessGeo.updatePolyNormalsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal); + tessGeo.polyNormalsBuffer.position(3 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 3 * offset * PGL.SIZEOF_FLOAT, 3 * size * PGL.SIZEOF_FLOAT, tessGeo.polyNormalsBuffer); + tessGeo.polyNormalsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4463,8 +4469,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyTexcoords(int offset, int size) { tessGeo.updatePolyTexcoordsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord); + tessGeo.polyTexcoordsBuffer.position(2 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT, 2 * size * PGL.SIZEOF_FLOAT, tessGeo.polyTexcoordsBuffer); + tessGeo.polyTexcoordsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4472,8 +4480,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyAmbient(int offset, int size) { tessGeo.updatePolyAmbientBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient); + tessGeo.polyAmbientBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, tessGeo.polyAmbientBuffer); + tessGeo.polyAmbientBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4481,8 +4491,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolySpecular(int offset, int size) { tessGeo.updatePolySpecularBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular); + tessGeo.polySpecularBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, tessGeo.polySpecularBuffer); + tessGeo.polySpecularBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4490,8 +4502,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyEmissive(int offset, int size) { tessGeo.updatePolyEmissiveBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive); + tessGeo.polyEmissiveBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, tessGeo.polyEmissiveBuffer); + tessGeo.polyEmissiveBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4499,8 +4513,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyShininess(int offset, int size) { tessGeo.updatePolyShininessBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess); + tessGeo.polyShininessBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_FLOAT, size * PGL.SIZEOF_FLOAT, tessGeo.polyShininessBuffer); + tessGeo.polyShininessBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4508,8 +4524,10 @@ public class PShapeOpenGL extends PShape { protected void copyLineVertices(int offset, int size) { tessGeo.updateLineVerticesBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex); + tessGeo.lineVerticesBuffer.position(4 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, tessGeo.lineVerticesBuffer); + tessGeo.lineVerticesBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4517,8 +4535,10 @@ public class PShapeOpenGL extends PShape { protected void copyLineColors(int offset, int size) { tessGeo.updateLineColorsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor); + tessGeo.lineColorsBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, tessGeo.lineColorsBuffer); + tessGeo.lineColorsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4526,8 +4546,10 @@ public class PShapeOpenGL extends PShape { protected void copyLineAttributes(int offset, int size) { tessGeo.updateLineAttribsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib); + tessGeo.lineAttribsBuffer.position(4 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, tessGeo.lineAttribsBuffer); + tessGeo.lineAttribsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4535,8 +4557,10 @@ public class PShapeOpenGL extends PShape { protected void copyPointVertices(int offset, int size) { tessGeo.updatePointVerticesBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex); + tessGeo.pointVerticesBuffer.position(4 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, tessGeo.pointVerticesBuffer); + tessGeo.pointVerticesBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4544,8 +4568,10 @@ public class PShapeOpenGL extends PShape { protected void copyPointColors(int offset, int size) { tessGeo.updatePointColorsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor); + tessGeo.pointColorsBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT,tessGeo.pointColorsBuffer); + tessGeo.pointColorsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4553,8 +4579,10 @@ public class PShapeOpenGL extends PShape { protected void copyPointAttributes(int offset, int size) { tessGeo.updatePointAttribsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib); + tessGeo.pointAttribsBuffer.position(2 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT, 2 * size * PGL.SIZEOF_FLOAT, tessGeo.pointAttribsBuffer); + tessGeo.pointAttribsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } From fea7ded2727c2c0724c6fed84f9671c4443bc4fe Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 17 Feb 2013 14:36:19 -0500 Subject: [PATCH 5/5] PShape.setStroke() uses color(255) in GroupPShape example --- .../Topics/Create Shapes/GroupPShape/GroupPShape.pde | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/java/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde b/java/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde index 05592f8ff..a8cbd0ab9 100644 --- a/java/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde +++ b/java/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde @@ -45,17 +45,15 @@ void setup() { // Make a primitive (Rectangle) PShape PShape rectangle = createShape(RECT,-10,-10,20,20); rectangle.setFill(false); - rectangle.setStroke(255); + rectangle.setStroke(color(255)); // Add them all to the group group.addChild(star); group.addChild(path); - group.addChild(rectangle); // Rectangle is missing??? - + group.addChild(rectangle); } void draw() { - // We can access them individually via the group PShape PShape rectangle = group.getChild(2); // Shapes can be rotated