Skip to content

Commit d82f12d

Browse files
committed
more p2dx test examples
1 parent 8d35ebd commit d82f12d

16 files changed

+653
-11
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifdef GL_ES
2+
precision mediump float;
3+
precision mediump int;
4+
#endif
5+
6+
#define PROCESSING_TEXTURE_SHADER
7+
8+
uniform sampler2D texture;
9+
uniform vec2 texOffset;
10+
11+
varying vec4 vertColor;
12+
varying vec4 vertTexCoord;
13+
14+
void main(void) {
15+
// Grouping texcoord variables in order to make it work in the GMA 950. See post #13
16+
// in this thread:
17+
// http://www.idevgames.com/forums/thread-3467.html
18+
vec2 tc0 = vertTexCoord.st + vec2(-texOffset.s, -texOffset.t);
19+
vec2 tc1 = vertTexCoord.st + vec2( 0.0, -texOffset.t);
20+
vec2 tc2 = vertTexCoord.st + vec2(+texOffset.s, -texOffset.t);
21+
vec2 tc3 = vertTexCoord.st + vec2(-texOffset.s, 0.0);
22+
vec2 tc4 = vertTexCoord.st + vec2( 0.0, 0.0);
23+
vec2 tc5 = vertTexCoord.st + vec2(+texOffset.s, 0.0);
24+
vec2 tc6 = vertTexCoord.st + vec2(-texOffset.s, +texOffset.t);
25+
vec2 tc7 = vertTexCoord.st + vec2( 0.0, +texOffset.t);
26+
vec2 tc8 = vertTexCoord.st + vec2(+texOffset.s, +texOffset.t);
27+
28+
vec4 col0 = texture2D(texture, tc0);
29+
vec4 col1 = texture2D(texture, tc1);
30+
vec4 col2 = texture2D(texture, tc2);
31+
vec4 col3 = texture2D(texture, tc3);
32+
vec4 col4 = texture2D(texture, tc4);
33+
vec4 col5 = texture2D(texture, tc5);
34+
vec4 col6 = texture2D(texture, tc6);
35+
vec4 col7 = texture2D(texture, tc7);
36+
vec4 col8 = texture2D(texture, tc8);
37+
38+
vec4 sum = (1.0 * col0 + 2.0 * col1 + 1.0 * col2 +
39+
2.0 * col3 + 4.0 * col4 + 2.0 * col4 +
40+
1.0 * col5 + 2.0 * col6 + 1.0 * col7) / 16.0;
41+
gl_FragColor = vec4(sum.rgb, 1.0) * vertColor;
42+
}
42.2 KB
Loading

debug/apps/fast2d/src/main/java/fast2d/MainActivity.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,19 @@
1111
import processing.core.PApplet;
1212

1313
public class MainActivity extends AppCompatActivity {
14-
// private int TEST = 0; // Basic self-intersecting polygon
15-
private int TEST = 1; // Mouse controlled polygon
16-
// private int TEST = 2; // Load and display SVG
14+
// private int TEST = 1; // Basic self-intersecting polygon
15+
// private int TEST = 2; // Mouse controlled polygon
16+
private int TEST = 3; // Textured poly
17+
// private int TEST = 4; // Text rendering
18+
// private int TEST = 5; // Shapes benchmark
19+
// private int TEST = 6; // Duplicated vertex
20+
// private int TEST = 7; // User-defined contours
21+
// private int TEST = 8; // Primitive types
22+
// private int TEST = 9; // Arc test
23+
// private int TEST = 10; // Arc test
24+
// private int TEST = 11; // Load and display SVG
25+
// private int TEST = 12; // Filter test
26+
// private int TEST = 13; // Custom shader test
1727

1828
private PApplet sketch;
1929

@@ -26,16 +36,34 @@ protected void onCreate(Bundle savedInstanceState) {
2636
ViewGroup.LayoutParams.MATCH_PARENT));
2737

2838

29-
if (TEST == 0) {
39+
if (TEST == 1) {
3040
sketch = new SketchBasicPoly();
31-
} else if (TEST == 1) {
32-
sketch = new SketchMousePoly();
3341
} else if (TEST == 2) {
42+
sketch = new SketchMousePoly();
43+
} else if (TEST == 3) {
44+
sketch = new SketchTexturedPoly();
45+
} else if (TEST == 4) {
46+
sketch = new SketchDisplayText();
47+
} else if (TEST == 5) {
48+
sketch = new SketchShapeBenchmark();
49+
} else if (TEST == 6) {
50+
sketch = new SketchDuplicatedVert();
51+
} else if (TEST == 7) {
52+
sketch = new SketchUserDefinedContours();
53+
} else if (TEST == 8) {
54+
sketch = new SketchPrimitiveTypes();
55+
} else if (TEST == 9) {
56+
sketch = new SketchArcTest();
57+
} else if (TEST == 10) {
58+
sketch = new SketchCurveTest();
59+
} else if (TEST == 11) {
3460
sketch = new SketchLoadDisplaySVG();
61+
} else if (TEST == 12) {
62+
sketch = new SketchFilterTest();
63+
} else if (TEST == 13) {
64+
sketch = new SketchCustomShader();
3565
}
3666

37-
38-
3967
PFragment fragment = new PFragment(sketch);
4068
fragment.setView(frame, this);
4169
}

debug/apps/fast2d/src/main/java/fast2d/Sketch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void draw() {
7676
// println("FRAME #" + frameCount);
7777
// println();
7878

79-
if (frameCount % 10 == 0) println((int)frameRate + " fps");
79+
if (frameCount % 10 == 0) println((int) frameRate + " fps");
8080

8181
strokeCap(cap);
8282
strokeJoin(join);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package fast2d;
2+
3+
import processing.core.PApplet;
4+
import processing.core.PVector;
5+
6+
public class SketchArcTest extends PApplet {
7+
float weight = 1;
8+
9+
int join = MITER;
10+
int cap = SQUARE;
11+
int mode = OPEN;
12+
13+
public void settings() {
14+
fullScreen(P2DX);
15+
}
16+
17+
public void setup() {
18+
strokeCap(cap);
19+
strokeJoin(join);
20+
}
21+
22+
public void draw() {
23+
background(255);
24+
25+
strokeWeight(4 * displayDensity);
26+
stroke(127, 0, 0);
27+
fill(255, 255, 255);
28+
29+
//testing the behavior of floating point % operator (for dealing with angles)
30+
float py = 0;
31+
for (int i = 0; i < width; ++i) {
32+
float x = (i - width/2) * 0.1f;
33+
float y = height/2 - (x % PI) * 10;
34+
line(i, y, i - 1, py);
35+
py = y;
36+
}
37+
38+
//testing the behavior of P2D arc() at various angles
39+
//NOTE: arcs with negative angle aren't drawn
40+
arc(100, 100, 100, 100, -1, new PVector(mouseX, mouseY).sub(100, 100).heading());
41+
42+
//test for whether LINES primitive type has self-overlap
43+
//NOTE: it does in JAVA2D, but not in P2D
44+
stroke(0, 127, 127, 127);
45+
beginShape(LINES);
46+
vertex(0, 0);
47+
vertex(width, height + 100);
48+
vertex(width, 0);
49+
vertex(0, height + 100);
50+
endShape();
51+
}
52+
}

debug/apps/fast2d/src/main/java/fast2d/SketchBasicPoly.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fast2d;
22

33
import processing.core.PApplet;
4-
import processing.core.PShape;
54

65
public class SketchBasicPoly extends PApplet {
76
float weight = 1;
@@ -23,6 +22,7 @@ public void draw() {
2322
background(255);
2423

2524
fill(255, 0, 63, 127);
25+
translate(100, 200);
2626

2727
strokeWeight(6 * weight * displayDensity);
2828
stroke(0, 127, 95, 191);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package fast2d;
2+
3+
import processing.core.PApplet;
4+
import processing.opengl.PGraphics2DX;
5+
6+
public class SketchCurveTest extends PApplet {
7+
int join = MITER;
8+
int cap = SQUARE;
9+
10+
public void settings() {
11+
fullScreen(P2DX);
12+
}
13+
14+
public void setup() {
15+
strokeCap(cap);
16+
strokeJoin(join);
17+
}
18+
19+
public void draw() {
20+
background(255);
21+
22+
//these cause errors in P4D because we haven't implemented them yet
23+
//so they're disabled in the demo for now
24+
if (getGraphics() instanceof PGraphics2DX) {
25+
return;
26+
}
27+
28+
noFill();
29+
stroke(0);
30+
strokeWeight(4 * displayDensity);
31+
pushMatrix();
32+
scale(2);
33+
34+
beginShape();
35+
curveVertex(84, 91);
36+
curveVertex(84, 91);
37+
curveVertex(68, 19);
38+
curveVertex(21, 17);
39+
curveVertex(32, 100);
40+
curveVertex(32, 100);
41+
endShape();
42+
43+
translate(100, 0);
44+
45+
beginShape();
46+
vertex(30, 20);
47+
bezierVertex(80, 0, 80, 75, 30, 75);
48+
bezierVertex(50, 80, 60, 25, 30, 20);
49+
endShape();
50+
51+
translate(100, 0);
52+
53+
beginShape();
54+
vertex(20, 20);
55+
quadraticVertex(80, 20, 50, 50);
56+
quadraticVertex(20, 80, 80, 80);
57+
vertex(80, 60);
58+
endShape();
59+
60+
popMatrix();
61+
}
62+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package fast2d;
2+
3+
import processing.core.PApplet;
4+
import processing.core.PImage;
5+
import processing.opengl.PShader;
6+
7+
public class SketchCustomShader extends PApplet {
8+
PShader edges;
9+
PImage img;
10+
boolean enabled = true;
11+
12+
public void settings() {
13+
fullScreen(P2DX);
14+
}
15+
16+
public void setup() {
17+
orientation(LANDSCAPE);
18+
img = loadImage("leaves.jpg");
19+
edges = loadShader("edges.glsl");
20+
}
21+
22+
public void draw() {
23+
if (enabled == true) {
24+
shader(edges);
25+
}
26+
image(img, 0, 0, width, height);
27+
}
28+
29+
public void mousePressed() {
30+
enabled = !enabled;
31+
if (!enabled == true) {
32+
resetShader();
33+
}
34+
}
35+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package fast2d;
2+
3+
import processing.core.PApplet;
4+
import processing.core.PFont;
5+
6+
public class SketchDisplayText extends PApplet {
7+
PFont font;
8+
9+
public void settings() {
10+
fullScreen(P2DX);
11+
}
12+
13+
public void setup() {
14+
font = createFont("SansSerif", displayDensity * 72);
15+
}
16+
17+
public void draw() {
18+
background(255);
19+
20+
textFont(font);
21+
text("Now is the time for all good men to come to the aid of their country.\n"
22+
+ "If they do not the quick brown fox may never jump over the lazy sleeping dog again.\n"
23+
+ "He may, however, take up knitting as a suitable hobby for all retired quick brown foxes.\n"
24+
+ "This is test #1 of 9,876,543,210.\n"
25+
+ "Collect them all!", 0, 100);
26+
}
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package fast2d;
2+
3+
import processing.core.PApplet;
4+
5+
public class SketchDuplicatedVert extends PApplet {
6+
int join = MITER;
7+
int cap = SQUARE;
8+
9+
public void settings() {
10+
fullScreen(P2DX);
11+
}
12+
13+
public void setup() {
14+
strokeCap(cap);
15+
strokeJoin(join);
16+
}
17+
18+
public void draw() {
19+
background(255);
20+
21+
//NOTE: yes, this produces the wrong result in P4D
22+
//see PGraphics4D.shapeVertex() for why
23+
beginShape();
24+
vertex(500, 300);
25+
vertex(600, 400); //dupe
26+
vertex(700, 300);
27+
vertex(650, 300);
28+
vertex(600, 400); //dupe
29+
vertex(550, 300);
30+
endShape(CLOSE);
31+
}
32+
}

0 commit comments

Comments
 (0)