diff --git a/android/examples/OpenGL/Camera/NearFar/NearFar.pde b/android/examples/OpenGL/Camera/NearFar/NearFar.pde
index 3ad438750..eb17f146a 100644
--- a/android/examples/OpenGL/Camera/NearFar/NearFar.pde
+++ b/android/examples/OpenGL/Camera/NearFar/NearFar.pde
@@ -1,3 +1,6 @@
+// Issues: The interaction is terrible on Android, and the visual cues are not
+// visible.
+
/**
* Near and Far example
*
@@ -55,7 +58,7 @@ void draw() {
if (usingPerspective) {
perspective(cameraFOV, float(width)/float(height), cameraNear, cameraFar);
} else {
- ortho(0, width, 0, height, cameraNear, cameraFar);
+ ortho(-width/2, width/2, -height/2, height/2, cameraNear, cameraFar);
}
pushMatrix();
diff --git a/android/examples/OpenGL/Camera/OrthoVSPerspective/OrthoVSPerspective.pde b/android/examples/OpenGL/Camera/OrthoVSPerspective/OrthoVSPerspective.pde
index d2daf0589..01e67a06b 100644
--- a/android/examples/OpenGL/Camera/OrthoVSPerspective/OrthoVSPerspective.pde
+++ b/android/examples/OpenGL/Camera/OrthoVSPerspective/OrthoVSPerspective.pde
@@ -13,16 +13,14 @@
* and maximum z values.
*/
-void setup()
-{
+void setup() {
size(640, 360, P3D);
orientation(LANDSCAPE);
noStroke();
fill(204);
}
-void draw()
-{
+void draw() {
background(0);
lights();
@@ -32,7 +30,7 @@ void draw()
perspective(fov, float(width)/float(height),
cameraZ/2.0, cameraZ*2.0);
} else {
- ortho(0, width, 0, height, 50, 500);
+ ortho(-width/2, width/2, -height/2, height/2, 0, 400);
}
translate(width/2, height/2, 0);
diff --git a/android/examples/OpenGL/Form/Toroid/Toroid.pde b/android/examples/OpenGL/Form/Toroid/Toroid.pde
index 5c7be22e4..776a9cf05 100644
--- a/android/examples/OpenGL/Form/Toroid/Toroid.pde
+++ b/android/examples/OpenGL/Form/Toroid/Toroid.pde
@@ -1,3 +1,6 @@
+// Strange "lights flashing" effect, particularly noticeable at low res (pts=10, segments=20)
+// ...some problem with the automatic normal calculation maybe?
+
/**
* Interactive Toroid
* by Ira Greenberg.
diff --git a/android/examples/OpenGL/IO/LoadSVG/LoadSVG.pde b/android/examples/OpenGL/IO/LoadSVG/LoadSVG.pde
index 725d3c0cd..3dcaf6c63 100644
--- a/android/examples/OpenGL/IO/LoadSVG/LoadSVG.pde
+++ b/android/examples/OpenGL/IO/LoadSVG/LoadSVG.pde
@@ -6,7 +6,7 @@ void setup() {
size(displayWidth, displayWidth, P2D);
orientation(LANDSCAPE);
- world = loadShape("World_map_with_nations.svg");
+ world = loadShape("World_map-lowres.svg");
PVector top = world.getTop();
world.translate(-top.x, -top.y);
diff --git a/android/examples/OpenGL/IO/LoadSVG/data/World_map-lowres.svg b/android/examples/OpenGL/IO/LoadSVG/data/World_map-lowres.svg
new file mode 100644
index 000000000..b587dd669
--- /dev/null
+++ b/android/examples/OpenGL/IO/LoadSVG/data/World_map-lowres.svg
@@ -0,0 +1,345 @@
+
+
+
\ No newline at end of file
diff --git a/android/examples/OpenGL/IO/LoadSVG/data/World_map_with_nations.svg b/android/examples/OpenGL/IO/LoadSVG/data/World_map_with_nations.svg
deleted file mode 100644
index fada0d8a9..000000000
--- a/android/examples/OpenGL/IO/LoadSVG/data/World_map_with_nations.svg
+++ /dev/null
@@ -1,419 +0,0 @@
-
-
\ No newline at end of file
diff --git a/android/examples/OpenGL/Image/Explode/Explode.pde b/android/examples/OpenGL/Image/Explode/Explode.pde
index 3e36940dd..259f5f368 100644
--- a/android/examples/OpenGL/Image/Explode/Explode.pde
+++ b/android/examples/OpenGL/Image/Explode/Explode.pde
@@ -1,3 +1,5 @@
+// Issues: the image appears corrupted...
+
/**
* Explode
* by Daniel Shiffman.
diff --git a/android/examples/OpenGL/Image/ExtrusionGL/ExtrusionGL.pde b/android/examples/OpenGL/Image/ExtrusionGL/ExtrusionGL.pde
index ac02e8106..850d88891 100644
--- a/android/examples/OpenGL/Image/ExtrusionGL/ExtrusionGL.pde
+++ b/android/examples/OpenGL/Image/ExtrusionGL/ExtrusionGL.pde
@@ -1,3 +1,5 @@
+// Lines appear repeated along horizontal strips (similar to Explode)
+
/**
* Extrusion.
*
diff --git a/android/examples/OpenGL/Immediate/Robot1_Draw/Robot1_Draw.pde b/android/examples/OpenGL/Immediate/Robot1_Draw/Robot1_Draw.pde
index 2238778c6..a4ec02989 100644
--- a/android/examples/OpenGL/Immediate/Robot1_Draw/Robot1_Draw.pde
+++ b/android/examples/OpenGL/Immediate/Robot1_Draw/Robot1_Draw.pde
@@ -1,3 +1,5 @@
+// Issues: some lines appear with wrong depth order
+
// Robot 1: Draw from "Getting Started with Processing"
// by Reas & Fry. O'Reilly / Make 2010
diff --git a/android/examples/OpenGL/Lights/CameraLight/CameraLight.pde b/android/examples/OpenGL/Lights/CameraLight/CameraLight.pde
index 551eb20b0..4d99aa00e 100644
--- a/android/examples/OpenGL/Lights/CameraLight/CameraLight.pde
+++ b/android/examples/OpenGL/Lights/CameraLight/CameraLight.pde
@@ -16,11 +16,8 @@ void draw() {
lights();
if (mousePressed) {
- // The arguments of ortho are specified in screen coordinates, where (0,0)
- // is the upper left corner of the screen
- ortho(0, width, 0, height);
+ ortho(-width/2, width/2, -height/2, height/2);
} else {
-
float fov = PI/3.0;
float cameraZ = (height/2.0) / tan(fov/2.0);
perspective(fov, float(width)/float(height),
diff --git a/android/examples/OpenGL/Performance/DynamicParticlesRetained/DynamicParticlesRetained.pde b/android/examples/OpenGL/Performance/DynamicParticlesRetained/DynamicParticlesRetained.pde
index c547b4c4b..7d2d696d9 100644
--- a/android/examples/OpenGL/Performance/DynamicParticlesRetained/DynamicParticlesRetained.pde
+++ b/android/examples/OpenGL/Performance/DynamicParticlesRetained/DynamicParticlesRetained.pde
@@ -63,8 +63,8 @@ void draw () {
if (lifetimes[n] == 0) {
// Re-spawn dead particle
- PVector center = part.getCenter();
- part.translate(mouseX - center.x, mouseY - center.y);
+ part.resetMatrix();
+ part.translate(mouseX, mouseY);
float angle = random(0, TWO_PI);
float s = random(0.5 * speed, 0.5 * speed);
velocities[n].x = s * cos(angle);
diff --git a/android/examples/OpenGL/Performance/Esfera/Esfera.pde b/android/examples/OpenGL/Performance/Esfera/Esfera.pde
index fd22225f4..b28463573 100644
--- a/android/examples/OpenGL/Performance/Esfera/Esfera.pde
+++ b/android/examples/OpenGL/Performance/Esfera/Esfera.pde
@@ -69,8 +69,6 @@ class pelo
float x = radio * cos(theta) * cos(phi);
float y = radio * cos(theta) * sin(phi);
float z = radio * sin(theta);
- float msx= screenX(x,y,z);
- float msy= screenY(x,y,z);
float xo = radio * cos(thetaff) * cos(phff);
float yo = radio * cos(thetaff) * sin(phff);
diff --git a/android/examples/OpenGL/Shaders/BlurFilter/BlurFilter.pde b/android/examples/OpenGL/Shaders/BlurFilter/BlurFilter.pde
new file mode 100644
index 000000000..9914df206
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/BlurFilter/BlurFilter.pde
@@ -0,0 +1,14 @@
+PShader blur;
+
+void setup() {
+ size(400, 400, P2D);
+ blur = loadShader("blur.glsl");
+}
+
+void draw() {
+ rect(mouseX, mouseY, 50, 50);
+ filter(blur);
+}
+
+
+
diff --git a/android/examples/OpenGL/Shaders/BlurFilter/data/blur.glsl b/android/examples/OpenGL/Shaders/BlurFilter/data/blur.glsl
new file mode 100644
index 000000000..b11a04d64
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/BlurFilter/data/blur.glsl
@@ -0,0 +1,48 @@
+#ifdef GL_ES
+precision mediump float;
+precision mediump int;
+#endif
+
+uniform sampler2D textureSampler;
+uniform vec2 texcoordOffset;
+
+varying vec4 vertColor;
+varying vec4 vertTexcoord;
+
+#define KERNEL_SIZE 9
+
+// Gaussian kernel
+// 1 2 1
+// 2 4 2
+// 1 2 1
+float kernel[KERNEL_SIZE];
+
+vec2 offset[KERNEL_SIZE];
+
+void main(void) {
+ int i = 0;
+ vec4 sum = vec4(0.0);
+
+ offset[0] = vec2(-texcoordOffset.s, -texcoordOffset.t);
+ offset[1] = vec2(0.0, -texcoordOffset.t);
+ offset[2] = vec2(texcoordOffset.s, -texcoordOffset.t);
+
+ offset[3] = vec2(-texcoordOffset.s, 0.0);
+ offset[4] = vec2(0.0, 0.0);
+ offset[5] = vec2(texcoordOffset.s, 0.0);
+
+ offset[6] = vec2(-texcoordOffset.s, texcoordOffset.t);
+ offset[7] = vec2(0.0, texcoordOffset.t);
+ offset[8] = vec2(texcoordOffset.s, texcoordOffset.t);
+
+ kernel[0] = 1.0/16.0; kernel[1] = 2.0/16.0; kernel[2] = 1.0/16.0;
+ kernel[3] = 2.0/16.0; kernel[4] = 4.0/16.0; kernel[5] = 2.0/16.0;
+ kernel[6] = 1.0/16.0; kernel[7] = 2.0/16.0; kernel[8] = 1.0/16.0;
+
+ for(i = 0; i < KERNEL_SIZE; i++) {
+ vec4 tmp = texture2D(textureSampler, vertTexcoord.st + offset[i]);
+ sum += tmp * kernel[i];
+ }
+
+ gl_FragColor = vec4(sum.rgb, 1.0) * vertColor;
+}
diff --git a/android/examples/OpenGL/Shaders/EdgeDetect/EdgeDetect.pde b/android/examples/OpenGL/Shaders/EdgeDetect/EdgeDetect.pde
index a190b4e80..6840399ea 100644
--- a/android/examples/OpenGL/Shaders/EdgeDetect/EdgeDetect.pde
+++ b/android/examples/OpenGL/Shaders/EdgeDetect/EdgeDetect.pde
@@ -5,17 +5,15 @@
// Press any key to switch between the custom and the default shader.
PImage img;
-PShader shader;
-PGraphicsOpenGL pg;
+PShader edges;
boolean customShader;
void setup() {
size(400, 400, P2D);
img = loadImage("berlin-1.jpg");
- pg = (PGraphicsOpenGL)g;
- shader = pg.loadShader("edges.glsl", PShader.TEXTURED);
- pg.setShader(shader, PShader.TEXTURED);
+ edges = loadShader(PShader.TEXTURED, "edges.glsl");
+ shader(edges);
customShader = true;
}
@@ -25,10 +23,10 @@ public void draw() {
public void mousePressed() {
if (customShader) {
- pg.defaultShader(PShader.TEXTURED);
+ resetShader(PShader.TEXTURED);
customShader = false;
} else {
- pg.setShader(shader, PShader.TEXTURED);
+ shader(edges);
customShader = true;
}
}
diff --git a/android/examples/OpenGL/Shaders/EdgeFilter/EdgeFilter.pde b/android/examples/OpenGL/Shaders/EdgeFilter/EdgeFilter.pde
new file mode 100644
index 000000000..59a81716c
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/EdgeFilter/EdgeFilter.pde
@@ -0,0 +1,34 @@
+// Issues: flickers and scene doesn't move
+
+PShader edges;
+boolean applyFilter = true;
+
+void setup() {
+ size(400, 400, P3D);
+ edges = loadShader("edges.glsl");
+ noStroke();
+}
+
+void draw() {
+ background(0);
+ lights();
+
+ translate(width/2, height/2);
+ pushMatrix();
+ rotateX(frameCount * 0.01);
+ rotateY(frameCount * 0.01);
+ box(100);
+ popMatrix();
+
+ if (applyFilter) filter(edges);
+
+ // The sphere doesn't have the edge detection applied
+ // on it because it is drawn after filter() is called.
+ rotateY(frameCount * 0.02);
+ translate(150, 0);
+ sphere(40);
+}
+
+void mousePressed() {
+ applyFilter = !applyFilter;
+}
diff --git a/android/examples/OpenGL/Shaders/EdgeFilter/data/edges.glsl b/android/examples/OpenGL/Shaders/EdgeFilter/data/edges.glsl
new file mode 100644
index 000000000..b032743d0
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/EdgeFilter/data/edges.glsl
@@ -0,0 +1,48 @@
+#ifdef GL_ES
+precision mediump float;
+precision mediump int;
+#endif
+
+uniform sampler2D textureSampler;
+uniform vec2 texcoordOffset;
+
+varying vec4 vertColor;
+varying vec4 vertTexcoord;
+
+#define KERNEL_SIZE 9
+
+// Edge detection kernel
+// -1 -1 -1
+// -1 +8 -1
+// -1 -1 -1
+float kernel[KERNEL_SIZE];
+
+vec2 offset[KERNEL_SIZE];
+
+void main(void) {
+ int i = 0;
+ vec4 sum = vec4(0.0);
+
+ offset[0] = vec2(-texcoordOffset.s, -texcoordOffset.t);
+ offset[1] = vec2(0.0, -texcoordOffset.t);
+ offset[2] = vec2(texcoordOffset.s, -texcoordOffset.t);
+
+ offset[3] = vec2(-texcoordOffset.s, 0.0);
+ offset[4] = vec2(0.0, 0.0);
+ offset[5] = vec2(texcoordOffset.s, 0.0);
+
+ offset[6] = vec2(-texcoordOffset.s, texcoordOffset.t);
+ offset[7] = vec2(0.0, texcoordOffset.t);
+ offset[8] = vec2(texcoordOffset.s, texcoordOffset.t);
+
+ kernel[0] = -1.0; kernel[1] = -1.0; kernel[2] = -1.0;
+ kernel[3] = -1.0; kernel[4] = 8.0; kernel[5] = -1.0;
+ kernel[6] = -1.0; kernel[7] = -1.0; kernel[8] = -1.0;
+
+ for(i = 0; i < KERNEL_SIZE; i++) {
+ vec4 tmp = texture2D(textureSampler, vertTexcoord.st + offset[i]);
+ sum += tmp * kernel[i];
+ }
+
+ gl_FragColor = vec4(sum.rgb, 1.0) * vertColor;
+}
diff --git a/android/examples/OpenGL/Shaders/FXAA/FXAA.pde b/android/examples/OpenGL/Shaders/FXAA/FXAA.pde
index cfea0f95b..92c10cd0a 100644
--- a/android/examples/OpenGL/Shaders/FXAA/FXAA.pde
+++ b/android/examples/OpenGL/Shaders/FXAA/FXAA.pde
@@ -6,8 +6,7 @@
PGraphics canvas;
boolean drawing = false;
-PGraphicsOpenGL pg;
-PShader shader;
+PShader fxaa;
boolean usingShader;
String message;
float msgLen;
@@ -20,9 +19,8 @@ void setup() {
canvas = createGraphics(width, height, P2D);
canvas.noSmooth();
- pg = (PGraphicsOpenGL) g;
- shader = pg.loadShader("fxaa.glsl", PShader.TEXTURED);
- pg.setShader(shader, PShader.TEXTURED);
+ fxaa = loadShader(PShader.TEXTURED, "fxaa.glsl");
+ shader(fxaa);
usingShader = true;
canvas.beginDraw();
@@ -56,10 +54,10 @@ public void draw() {
public void mousePressed() {
if (!drawing && width - msgLen < mouseX && height - 23 < mouseY) {
if (usingShader) {
- pg.defaultShader(PShader.TEXTURED);
+ resetShader(PShader.TEXTURED);
usingShader = false;
} else {
- pg.setShader(shader, PShader.TEXTURED);
+ shader(fxaa);
usingShader = true;
}
updateMessage();
@@ -85,11 +83,11 @@ void drawMessage() {
if (usingShader) {
// We need the default texture shader to
// render text.
- pg.defaultShader(PShader.TEXTURED);
+ resetShader(PShader.TEXTURED);
}
fill(0);
text(message, width - msgLen, height - 5);
if (usingShader) {
- pg.setShader(shader, PShader.TEXTURED);
+ shader(fxaa);
}
}
diff --git a/android/examples/OpenGL/Shaders/FishEye/FishEye.pde b/android/examples/OpenGL/Shaders/FishEye/FishEye.pde
new file mode 100644
index 000000000..782c46999
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/FishEye/FishEye.pde
@@ -0,0 +1,40 @@
+// Issues: crashes with
+// java.lang.RuntimeException: can only create 8 lights
+
+// Fish-eye shader, useful for dome projection
+
+PGraphics canvas;
+PShader fisheye;
+PImage img;
+
+void setup() {
+ size(400, 400, P3D);
+ canvas = createGraphics(400, 400, P3D);
+
+ fisheye = loadShader(PShader.TEXTURED, "FishEye.glsl");
+ fisheye.set("aperture", 180.0);
+ shader(fisheye);
+}
+
+void draw() {
+ canvas.beginDraw();
+ canvas.background(0);
+ canvas.stroke(255, 0, 0);
+ for (int i = 0; i < width; i += 10) {
+ canvas.line(i, 0, i, height);
+ }
+ for (int i = 0; i < height; i += 10) {
+ canvas.line(0, i, width, i);
+ }
+ canvas.lights();
+ canvas.noStroke();
+ canvas.translate(mouseX, mouseY, 100);
+ canvas.rotateX(frameCount * 0.01f);
+ canvas.rotateY(frameCount * 0.01f);
+ canvas.box(50);
+ canvas.endDraw();
+
+ // The rendering of this image will be done through the fisheye shader, since
+ // it was set as the PShader.TEXTURED shader of the main surface.
+ image(canvas, 0, 0, width, height);
+}
diff --git a/android/examples/OpenGL/Shaders/FishEye/data/FishEye.glsl b/android/examples/OpenGL/Shaders/FishEye/data/FishEye.glsl
new file mode 100644
index 000000000..398fdbd9d
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/FishEye/data/FishEye.glsl
@@ -0,0 +1,51 @@
+// Inspired by the "Angular Fisheye à la Bourke" sketch from
+// Jonathan Cremieux, as shown in the OpenProcessing website:
+// http://openprocessing.org/visuals/?visualID=12140
+// Using the inverse transform of the angular fisheye as
+// explained in Paul Bourke's website:
+// http://paulbourke.net/miscellaneous/domefisheye/fisheye/
+
+#ifdef GL_ES
+precision mediump float;
+precision mediump int;
+#endif
+
+uniform sampler2D textureSampler;
+varying vec4 vertColor;
+varying vec4 vertTexcoord;
+
+uniform float aperture;
+
+const float PI = 3.1415926535;
+
+void main(void) {
+ float apertureHalf = 0.5 * aperture * (PI / 180.0);
+
+ // This factor ajusts the coordinates in the case that
+ // the aperture angle is less than 180 degrees, in which
+ // case the area displayed is not the entire half-sphere.
+ float maxFactor = sin(apertureHalf);
+
+ vec2 pos = 2.0 * vertTexcoord.st - 1.0;
+
+ float l = length(pos);
+ if (l > 1.0) {
+ gl_FragColor = vec4(0, 0, 0, 1);
+ } else {
+ float x = maxFactor * pos.x;
+ float y = maxFactor * pos.y;
+
+ float n = length(vec2(x, y));
+
+ float z = sqrt(1.0 - n * n);
+
+ float r = atan(n, z) / PI;
+
+ float phi = atan(y, x);
+
+ float u = r * cos(phi) + 0.5;
+ float v = r * sin(phi) + 0.5;
+
+ gl_FragColor = texture2D(textureSampler, vec2(u, v)) * vertColor;
+ }
+}
\ No newline at end of file
diff --git a/android/examples/OpenGL/Shaders/GlossyFishEye/GlossyFishEye.pde b/android/examples/OpenGL/Shaders/GlossyFishEye/GlossyFishEye.pde
new file mode 100644
index 000000000..31f198d51
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/GlossyFishEye/GlossyFishEye.pde
@@ -0,0 +1,72 @@
+// Issues: same as FishEye
+
+// Fish-eye shader on the main surface, glossy specular reflection shader
+// on the offscreen canvas.
+
+PGraphics canvas;
+PShader fisheye;
+PShader glossy;
+PImage img;
+PShape ball;
+
+boolean usingFishEye;
+
+void setup() {
+ size(400, 400, P3D);
+ canvas = createGraphics(400, 400, P3D);
+
+ fisheye = loadShader(PShader.TEXTURED, "FishEye.glsl");
+ fisheye.set("aperture", 180.0);
+ shader(fisheye);
+ usingFishEye = true;
+
+ glossy = loadShader(PShader.LIT, "GlossyFrag.glsl", "GlossyVert.glsl");
+ glossy.set("AmbientColour", 0, 0, 0);
+ glossy.set("DiffuseColour", 0.9, 0.2, 0.2);
+ glossy.set("SpecularColour", 1.0, 1.0, 1.0);
+ glossy.set("AmbientIntensity", 1.0);
+ glossy.set("DiffuseIntensity", 1.0);
+ glossy.set("SpecularIntensity", 0.7);
+ glossy.set("Roughness", 0.7);
+ glossy.set("Sharpness", 0.0);
+ canvas.shader(glossy);
+
+ ball = createShape(SPHERE, 50);
+ //ball.fill(200, 50, 50);
+ ball.noStroke();
+}
+
+void draw() {
+ canvas.beginDraw();
+ canvas.noStroke();
+ canvas.background(0);
+ canvas.pushMatrix();
+ canvas.rotateY(frameCount * 0.01);
+ canvas.pointLight(204, 204, 204, 1000, 1000, 1000);
+ canvas.popMatrix();
+ for (float x = 0; x < canvas.width + 100; x += 100) {
+ for (float y = 0; y < canvas.height + 100; y += 100) {
+ for (float z = 0; z < 200; z += 100) {
+ canvas.pushMatrix();
+ canvas.translate(x, y, -z);
+ canvas.shape(ball);
+ canvas.popMatrix();
+ }
+ }
+ }
+ canvas.endDraw();
+
+ image(canvas, 0, 0, width, height);
+
+ println(frameRate);
+}
+
+public void mousePressed() {
+ if (usingFishEye) {
+ resetShader(PShader.TEXTURED);
+ usingFishEye = false;
+ } else {
+ shader(fisheye);
+ usingFishEye = true;
+ }
+}
diff --git a/android/examples/OpenGL/Shaders/GlossyFishEye/data/FishEye.glsl b/android/examples/OpenGL/Shaders/GlossyFishEye/data/FishEye.glsl
new file mode 100644
index 000000000..398fdbd9d
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/GlossyFishEye/data/FishEye.glsl
@@ -0,0 +1,51 @@
+// Inspired by the "Angular Fisheye à la Bourke" sketch from
+// Jonathan Cremieux, as shown in the OpenProcessing website:
+// http://openprocessing.org/visuals/?visualID=12140
+// Using the inverse transform of the angular fisheye as
+// explained in Paul Bourke's website:
+// http://paulbourke.net/miscellaneous/domefisheye/fisheye/
+
+#ifdef GL_ES
+precision mediump float;
+precision mediump int;
+#endif
+
+uniform sampler2D textureSampler;
+varying vec4 vertColor;
+varying vec4 vertTexcoord;
+
+uniform float aperture;
+
+const float PI = 3.1415926535;
+
+void main(void) {
+ float apertureHalf = 0.5 * aperture * (PI / 180.0);
+
+ // This factor ajusts the coordinates in the case that
+ // the aperture angle is less than 180 degrees, in which
+ // case the area displayed is not the entire half-sphere.
+ float maxFactor = sin(apertureHalf);
+
+ vec2 pos = 2.0 * vertTexcoord.st - 1.0;
+
+ float l = length(pos);
+ if (l > 1.0) {
+ gl_FragColor = vec4(0, 0, 0, 1);
+ } else {
+ float x = maxFactor * pos.x;
+ float y = maxFactor * pos.y;
+
+ float n = length(vec2(x, y));
+
+ float z = sqrt(1.0 - n * n);
+
+ float r = atan(n, z) / PI;
+
+ float phi = atan(y, x);
+
+ float u = r * cos(phi) + 0.5;
+ float v = r * sin(phi) + 0.5;
+
+ gl_FragColor = texture2D(textureSampler, vec2(u, v)) * vertColor;
+ }
+}
\ No newline at end of file
diff --git a/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyFrag.glsl b/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyFrag.glsl
new file mode 100644
index 000000000..4f96b6f6d
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyFrag.glsl
@@ -0,0 +1,45 @@
+// Copyright (C) 2007 Dave Griffiths
+// Copyright (C) 2007 Dave Griffiths
+// Licence: GPLv2 (see COPYING)
+// Fluxus Shader Library
+// ---------------------
+// Glossy Specular Reflection Shader
+// A more controllable version of blinn shading,
+// Useful for ceramic or fluids - from Advanced
+// Renderman, thanks to Larry Gritz
+
+#ifdef GL_ES
+precision mediump float;
+precision mediump int;
+#endif
+
+uniform vec3 AmbientColour;
+uniform vec3 DiffuseColour;
+uniform vec3 SpecularColour;
+uniform float AmbientIntensity;
+uniform float DiffuseIntensity;
+uniform float SpecularIntensity;
+uniform float Roughness;
+uniform float Sharpness;
+
+varying vec3 N;
+varying vec3 P;
+varying vec3 V;
+varying vec3 L;
+
+void main()
+{
+ float w = 0.18*(1.0-Sharpness);
+
+ vec3 l = normalize(L);
+ vec3 n = normalize(N);
+ vec3 v = normalize(V);
+ vec3 h = normalize(l+v);
+
+ float diffuse = dot(l,n);
+ float specular = smoothstep(0.72-w,0.72+w,pow(max(0.0,dot(n,h)),1.0/Roughness));
+
+ gl_FragColor = vec4(AmbientColour*AmbientIntensity +
+ DiffuseColour*diffuse*DiffuseIntensity +
+ SpecularColour*specular*SpecularIntensity,1);
+}
diff --git a/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyVert.glsl b/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyVert.glsl
new file mode 100644
index 000000000..fa0c29590
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/GlossyFishEye/data/GlossyVert.glsl
@@ -0,0 +1,31 @@
+// Copyright (C) 2007 Dave Griffiths
+// Licence: GPLv2 (see COPYING)
+// Fluxus Shader Library
+// ---------------------
+// Glossy Specular Reflection Shader
+// A more controllable version of blinn shading,
+// Useful for ceramic or fluids - from Advanced
+// Renderman, thanks to Larry Gritz
+
+uniform mat4 modelviewMatrix;
+uniform mat4 projmodelviewMatrix;
+uniform mat3 normalMatrix;
+
+uniform vec4 lightPosition[8];
+
+attribute vec4 inVertex;
+attribute vec3 inNormal;
+
+varying vec3 N;
+varying vec3 P;
+varying vec3 V;
+varying vec3 L;
+
+void main() {
+ N = normalize(normalMatrix * inNormal);
+ P = inVertex.xyz;
+ V = -vec3(modelviewMatrix * inVertex);
+ L = vec3(modelviewMatrix * (lightPosition[0] - inVertex));
+ gl_Position = projmodelviewMatrix * inVertex;
+}
+
diff --git a/android/examples/OpenGL/Shaders/LowLevelGL/LowLevelGL.pde b/android/examples/OpenGL/Shaders/LowLevelGL/LowLevelGL.pde
new file mode 100644
index 000000000..a8f9ef4fb
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/LowLevelGL/LowLevelGL.pde
@@ -0,0 +1,102 @@
+// Draws a triangle using low-level OpenGL calls.
+import java.nio.FloatBuffer;
+
+PGraphicsOpenGL pg;
+PGL pgl;
+
+PShader flatShader;
+
+int vertLoc;
+int colorLoc;
+
+float[] vertices;
+float[] colors;
+
+FloatBuffer vertData;
+FloatBuffer colorData;
+
+void setup() {
+ size(400, 400, P3D);
+
+ pg = (PGraphicsOpenGL)g;
+
+ // Get the default shader that Processing uses to
+ // render flat geometry (w/out textures and lights).
+ flatShader = getShader(PShader.FLAT);
+
+ vertices = new float[12];
+ vertData = PGL.allocateDirectFloatBuffer(12);
+
+ colors = new float[12];
+ colorData = PGL.allocateDirectFloatBuffer(12);
+}
+
+void draw() {
+ background(0);
+
+ // The geometric transformations will be automatically passed
+ // to the shader.
+ rotate(frameCount * 0.01f, width, height, 0);
+
+ updateGeometry();
+
+ pgl = pg.beginGL();
+ flatShader.bind();
+
+ vertLoc = pgl.glGetAttribLocation(flatShader.glProgram, "inVertex");
+ colorLoc = pgl.glGetAttribLocation(flatShader.glProgram, "inColor");
+
+ pgl.glEnableVertexAttribArray(vertLoc);
+ pgl.glEnableVertexAttribArray(colorLoc);
+
+ pgl.glVertexAttribPointer(vertLoc, 4, PGL.GL_FLOAT, false, 0, vertData);
+ pgl.glVertexAttribPointer(colorLoc, 4, PGL.GL_FLOAT, false, 0, colorData);
+
+ pgl.glDrawArrays(PGL.GL_TRIANGLES, 0, 3);
+
+ pgl.glDisableVertexAttribArray(vertLoc);
+ pgl.glDisableVertexAttribArray(colorLoc);
+
+ flatShader.unbind();
+ pg.endGL();
+}
+
+void updateGeometry() {
+ // Vertex 1
+ vertices[0] = 0;
+ vertices[1] = 0;
+ vertices[2] = 0;
+ vertices[3] = 1;
+ colors[0] = 1;
+ colors[1] = 0;
+ colors[2] = 0;
+ colors[3] = 1;
+
+ // Corner 2
+ vertices[4] = width/2;
+ vertices[5] = height;
+ vertices[6] = 0;
+ vertices[7] = 1;
+ colors[4] = 0;
+ colors[5] = 1;
+ colors[6] = 0;
+ colors[7] = 1;
+
+ // Corner 3
+ vertices[8] = width;
+ vertices[9] = 0;
+ vertices[10] = 0;
+ vertices[11] = 1;
+ colors[8] = 0;
+ colors[9] = 0;
+ colors[10] = 1;
+ colors[11] = 1;
+
+ vertData.rewind();
+ vertData.put(vertices);
+ vertData.position(0);
+
+ colorData.rewind();
+ colorData.put(colors);
+ colorData.position(0);
+}
diff --git a/android/examples/OpenGL/Shaders/SepBlur/SepBlur.pde b/android/examples/OpenGL/Shaders/SepBlur/SepBlur.pde
new file mode 100644
index 000000000..d16bf1d85
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/SepBlur/SepBlur.pde
@@ -0,0 +1,65 @@
+// Issues: shader cannot be compiled:
+// (48) : error C5013: profile does not support "for" statements and "for" could not be unrolled.
+
+// Separable-blur shader (works by applying two successive passes
+// in each direction of the image)
+
+PShader blur;
+PGraphics src;
+PGraphics pass1, pass2;
+
+void setup() {
+ size(200, 200, P2D);
+
+ blur = loadShader(PShader.TEXTURED, "blur.glsl");
+ blur.set("blurSize", 9);
+ blur.set("sigma", 5.0f);
+
+ src = createGraphics(width, height, P2D);
+
+ pass1 = createGraphics(width, height, P2D);
+ pass1.noSmooth();
+ pass1.shader(blur);
+
+ pass2 = createGraphics(width, height, P2D);
+ pass2.noSmooth();
+ pass2.shader(blur);
+}
+
+void draw() {
+ src.beginDraw();
+ src.background(0);
+ src.fill(255);
+ src.ellipse(width/2, height/2, 100, 100);
+ src.endDraw();
+
+ // Applying the blur shader along the vertical direction
+ blur.set("horizontalPass", 0);
+ pass1.beginDraw();
+ pass1.image(src, 0, 0);
+ pass1.endDraw();
+
+ // Applying the blur shader along the horizontal direction
+ blur.set("horizontalPass", 1);
+ pass2.beginDraw();
+ pass2.image(pass1, 0, 0);
+ pass2.endDraw();
+
+ image(pass2, 0, 0);
+}
+
+void keyPressed() {
+ if (key == '9') {
+ blur.set("blurSize", 9);
+ blur.set("sigma", 5.0);
+ } else if (key == '7') {
+ blur.set("blurSize", 7);
+ blur.set("sigma", 3.0);
+ } else if (key == '5') {
+ blur.set("blurSize", 5);
+ blur.set("sigma", 2.0);
+ } else if (key == '3') {
+ blur.set("blurSize", 5);
+ blur.set("sigma", 1.0);
+ }
+}
diff --git a/android/examples/OpenGL/Shaders/SepBlur/data/blur.glsl b/android/examples/OpenGL/Shaders/SepBlur/data/blur.glsl
new file mode 100644
index 000000000..bba029e7f
--- /dev/null
+++ b/android/examples/OpenGL/Shaders/SepBlur/data/blur.glsl
@@ -0,0 +1,57 @@
+// Adapted from:
+// http://callumhay.blogspot.com/2010/09/gaussian-blur-shader-glsl.html
+
+#ifdef GL_ES
+precision mediump float;
+precision mediump int;
+#endif
+
+uniform sampler2D textureSampler;
+
+// The inverse of the texture dimensions along X and Y
+uniform vec2 texcoordOffset;
+
+varying vec4 vertColor;
+varying vec4 vertTexcoord;
+
+uniform int blurSize;
+uniform int horizontalPass; // 0 or 1 to indicate vertical or horizontal pass
+uniform float sigma; // The sigma value for the gaussian function: higher value means more blur
+ // A good value for 9x9 is around 3 to 5
+ // A good value for 7x7 is around 2.5 to 4
+ // A good value for 5x5 is around 2 to 3.5
+ // ... play around with this based on what you need :)
+
+const float pi = 3.14159265;
+
+void main() {
+ float numBlurPixelsPerSide = float(blurSize / 2);
+
+ vec2 blurMultiplyVec = 0 < horizontalPass ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
+
+ // Incremental Gaussian Coefficent Calculation (See GPU Gems 3 pp. 877 - 889)
+ vec3 incrementalGaussian;
+ incrementalGaussian.x = 1.0 / (sqrt(2.0 * pi) * sigma);
+ incrementalGaussian.y = exp(-0.5 / (sigma * sigma));
+ incrementalGaussian.z = incrementalGaussian.y * incrementalGaussian.y;
+
+ vec4 avgValue = vec4(0.0, 0.0, 0.0, 0.0);
+ float coefficientSum = 0.0;
+
+ // Take the central sample first...
+ avgValue += texture2D(textureSampler, vertTexcoord.st) * incrementalGaussian.x;
+ coefficientSum += incrementalGaussian.x;
+ incrementalGaussian.xy *= incrementalGaussian.yz;
+
+ // Go through the remaining 8 vertical samples (4 on each side of the center)
+ for (float i = 1.0; i <= numBlurPixelsPerSide; i++) {
+ avgValue += texture2D(textureSampler, vertTexcoord.st - i * texcoordOffset *
+ blurMultiplyVec) * incrementalGaussian.x;
+ avgValue += texture2D(textureSampler, vertTexcoord.st + i * texcoordOffset *
+ blurMultiplyVec) * incrementalGaussian.x;
+ coefficientSum += 2.0 * incrementalGaussian.x;
+ incrementalGaussian.xy *= incrementalGaussian.yz;
+ }
+
+ gl_FragColor = avgValue / coefficientSum;
+}
\ No newline at end of file
diff --git a/android/examples/OpenGL/Shaders/ToonShading/ToonShading.pde b/android/examples/OpenGL/Shaders/ToonShading/ToonShading.pde
index 5d24eed73..c5cb11350 100644
--- a/android/examples/OpenGL/Shaders/ToonShading/ToonShading.pde
+++ b/android/examples/OpenGL/Shaders/ToonShading/ToonShading.pde
@@ -3,8 +3,7 @@
// Based on the glsl tutorial from lighthouse 3D:
// http://www.lighthouse3d.com/tutorials/glsl-tutorial/toon-shader-version-ii/
-PShader shader;
-PGraphicsOpenGL pg;
+PShader toon;
boolean customShader;
public void setup() {
@@ -12,9 +11,8 @@ public void setup() {
noStroke();
fill(204);
- pg = (PGraphicsOpenGL)g;
- shader = pg.loadShader("ToonVert.glsl", "ToonFrag.glsl", PShader.LIT);
- pg.setShader(shader, PShader.LIT);
+ toon = loadShader(PShader.LIT, "ToonFrag.glsl", "ToonVert.glsl");
+ shader(toon);
customShader = true;
}
@@ -31,12 +29,13 @@ public void draw() {
public void mousePressed() {
if (dist(mouseX, mouseY, width/2, height/2) < 80) {
if (customShader) {
- pg.defaultShader(PShader.LIT);
+ resetShader(PShader.LIT);
customShader = false;
}
else {
- pg.setShader(shader, PShader.LIT);
+ shader(toon);
customShader = true;
}
}
}
+
diff --git a/android/examples/OpenGL/Tests/OffscreenTest/OffscreenTest.pde b/android/examples/OpenGL/Tests/OffscreenTest/OffscreenTest.pde
index 335bdeb1e..0244b3521 100644
--- a/android/examples/OpenGL/Tests/OffscreenTest/OffscreenTest.pde
+++ b/android/examples/OpenGL/Tests/OffscreenTest/OffscreenTest.pde
@@ -4,7 +4,6 @@ void setup() {
size(400, 400, P3D);
pg = createGraphics(400, 400, P3D);
- pg.smooth(4);
}
void draw() {
@@ -18,15 +17,3 @@ void draw() {
image(pg, 0, 0, 400, 400);
}
-void keyPressed() {
- if (key == '1') pg.smooth(1);
- else if (key == '2') pg.smooth(2);
- else if (key == '3') pg.smooth(4);
- else if (key == '4') pg.smooth(8);
- else if (key == '5') pg.smooth(16);
- else if (key == '6') pg.smooth(32);
- else if (key == ' ') {
- ((PGraphicsOpenGL)g).restartPGL();
- }
-}
-
diff --git a/android/examples/OpenGL/Tests/RedrawTest/RedrawTest.pde b/android/examples/OpenGL/Tests/RedrawTest/RedrawTest.pde
index 7cd352736..9a6c4c16c 100644
--- a/android/examples/OpenGL/Tests/RedrawTest/RedrawTest.pde
+++ b/android/examples/OpenGL/Tests/RedrawTest/RedrawTest.pde
@@ -1,3 +1,5 @@
+// Issues: doesn't redraw
+
void setup() {
size(400, 400, P3D);
noLoop();
diff --git a/android/examples/OpenGL/Tests/RestartTest/RestartTest.pde b/android/examples/OpenGL/Tests/RestartTest/RestartTest.pde
deleted file mode 100644
index 256a71c6e..000000000
--- a/android/examples/OpenGL/Tests/RestartTest/RestartTest.pde
+++ /dev/null
@@ -1,26 +0,0 @@
-PShape cube;
-
-void setup() {
- size(400, 400, P3D);
-
- cube = createShape(BOX, 100);
-}
-
-void draw() {
- background(120);
-
- lights();
-
- translate(mouseX, mouseY);
- rotateX(frameCount * 0.01f);
- rotateY(frameCount * 0.01f);
-
- shape(cube);
-}
-
-void keyPressed() {
- // Restarts the OpenGL surface. Automatically
- // recreates all the current GL resources.
- ((PGraphicsOpenGL)g).restartPGL();
-}
-
diff --git a/android/examples/OpenGL/Transform/Bird/Bird.pde b/android/examples/OpenGL/Transform/Bird/Bird.pde
index 851d8d7a4..686c08c63 100644
--- a/android/examples/OpenGL/Transform/Bird/Bird.pde
+++ b/android/examples/OpenGL/Transform/Bird/Bird.pde
@@ -1,3 +1,6 @@
+// Issues: the entire screen is white for a second at the beginning, then
+// the wings of the bird are black
+
/**
* Simple 3D Bird
* by Ira Greenberg.
diff --git a/android/examples/OpenGL/Transform/Birds/Birds.pde b/android/examples/OpenGL/Transform/Birds/Birds.pde
index 959de37f7..f4088489c 100644
--- a/android/examples/OpenGL/Transform/Birds/Birds.pde
+++ b/android/examples/OpenGL/Transform/Birds/Birds.pde
@@ -1,3 +1,6 @@
+// Issues: the entire screen is white for a second at the beginning, then
+// the wings of the birds are black
+
/**
* Crazy Flocking 3D Birds
* by Ira Greenberg.
diff --git a/android/examples/OpenGL/Transform/PushPopCubes/PushPopCubes.pde b/android/examples/OpenGL/Transform/PushPopCubes/PushPopCubes.pde
index 0912a3ce9..21b252b74 100644
--- a/android/examples/OpenGL/Transform/PushPopCubes/PushPopCubes.pde
+++ b/android/examples/OpenGL/Transform/PushPopCubes/PushPopCubes.pde
@@ -28,7 +28,7 @@ void setup(){
// instantiate cubes
for (int i = 0; i < cubeCount; i++){
- cubes[i] = new Cube(12, 12, 6, 0, 0, 0);
+ cubes[i] = new Cube(24, 20, 10, 0, 0, 0);
/* 3 different rotation options
- 1st option: cubes each rotate uniformly
- 2nd option: cubes each rotate randomly