1
1
package ch .bildspur .postfx ;
2
2
3
3
import ch .bildspur .postfx .builder .PostFX ;
4
+ import ch .bildspur .postfx .builder .PostFXBuilder ;
4
5
import processing .core .PApplet ;
6
+ import processing .core .PGraphics ;
7
+
8
+ import java .lang .reflect .Field ;
9
+ import java .util .Arrays ;
10
+ import java .util .Collection ;
11
+ import java .util .Comparator ;
12
+ import java .util .TreeSet ;
5
13
6
14
/**
7
15
* Created by cansik on 21.03.17.
8
16
*/
9
17
public class SimpleSketch extends PApplet {
10
18
PostFX fx ;
19
+ PGraphics canvas ;
20
+
21
+ boolean renderOnCanvas = false ;
11
22
12
23
public static void main (String ... args ) {
13
24
SimpleSketch sketch = new SimpleSketch ();
@@ -16,43 +27,101 @@ public static void main(String... args) {
16
27
17
28
public void settings () {
18
29
size (720 , 720 , P3D );
19
- pixelDensity (2 );
30
+ pixelDensity (1 );
20
31
}
21
32
22
33
public void setup () {
23
34
fx = new PostFX (this );
35
+
36
+ canvas = createGraphics (width , height , P3D );
24
37
}
25
38
26
39
public void draw () {
27
- // clear screen
28
40
background (0 );
29
41
30
- fill (255 );
31
- ellipse (width / 2 , height / 2 , width * 0.75f , height * 0.75f );
42
+ if (renderOnCanvas ) {
43
+ canvas .beginDraw ();
44
+ renderExample (canvas );
45
+ canvas .endDraw ();
46
+ } else {
47
+ renderExample (g );
48
+ }
49
+
50
+ // add effect
51
+ PostFXBuilder fxb ;
52
+
53
+ if (renderOnCanvas ) {
54
+ fxb = fx .render (this .canvas );
55
+ } else {
56
+ fxb = fx .render ();
57
+ }
58
+
59
+ fxb = fxb .bloom (0.8f , 30 , 50 );
60
+
61
+ background (0 );
62
+ if (renderOnCanvas ) {
63
+ fxb .compose (canvas );
64
+ image (canvas , 0 , 0 );
65
+ } else {
66
+ fxb .compose ();
67
+ }
68
+
69
+ fill (0 , 255 , 0 );
70
+ text ("FPS: " + frameRate , 20 , 20 );
71
+ text ("Rendering: " + ((renderOnCanvas ) ? "Canvas" : "Screen" ), 20 , 50 );
72
+ }
73
+
74
+ void renderExample (PGraphics graphics ) {
75
+ // clear screen
76
+ graphics .background (0 );
77
+
78
+ graphics .fill (255 );
79
+ graphics .ellipse (width / 2 , height / 2 , width * 0.75f , height * 0.75f );
32
80
33
81
// render simple cube
34
- pushMatrix ();
82
+ graphics . pushMatrix ();
35
83
36
- translate (width / 2f , height / 2f );
37
- rotateX (radians (frameCount % 360 ));
38
- rotateZ (radians (frameCount % 360 ));
84
+ graphics . translate (width / 2f , height / 2f );
85
+ graphics . rotateX (radians (frameCount % 360 ));
86
+ graphics . rotateZ (radians (frameCount % 360 ));
39
87
40
- noStroke ();
41
- fill (20 , 20 , 20 );
42
- box (100 );
88
+ graphics . noStroke ();
89
+ graphics . fill (20 , 20 , 20 );
90
+ graphics . box (100 );
43
91
44
- fill (150 , 255 , 255 );
45
- sphere (60 );
92
+ graphics . fill (150 , 255 , 255 );
93
+ graphics . sphere (60 );
46
94
47
- popMatrix ();
95
+ graphics .popMatrix ();
96
+ }
48
97
49
- // add effect
50
- fx .render ()
51
- .bloom (0.8f , 30 , 50 )
52
- .toneMapping (1.2f )
53
- .compose ();
98
+ @ Override
99
+ public void keyPressed () {
100
+ super .keyPressed ();
54
101
55
- fill (0 , 255 , 0 );
56
- text ("FPS: " + frameRate , 20 , 20 );
102
+ renderOnCanvas = !renderOnCanvas ;
103
+ }
104
+
105
+ public static Collection <Field > getAllFields (Class <?> type ) {
106
+ TreeSet <Field > fields = new TreeSet <Field >(
107
+ Comparator .comparing (Field ::getName ).thenComparing (o -> o .getDeclaringClass ().getSimpleName ()).thenComparing (o -> o .getDeclaringClass ().getName ()));
108
+ for (Class <?> c = type ; c != null ; c = c .getSuperclass ()) {
109
+ fields .addAll (Arrays .asList (c .getDeclaredFields ()));
110
+ }
111
+ return fields ;
112
+ }
113
+
114
+ public static void printAllFields (Object obj ) {
115
+ for (Field field : getAllFields (obj .getClass ())) {
116
+ field .setAccessible (true );
117
+ String name = field .getName ();
118
+ Object value = null ;
119
+ try {
120
+ value = field .get (obj );
121
+ } catch (IllegalArgumentException | IllegalAccessException e ) {
122
+ e .printStackTrace ();
123
+ }
124
+ System .out .printf ("%s %s.%s = %s;\n " , value == null ? " " : "*" , field .getDeclaringClass ().getSimpleName (), name , value );
125
+ }
57
126
}
58
127
}
0 commit comments