Skip to content

Commit 325f953

Browse files
committed
Updated Examples - Frames are now resize-able
1 parent 7eeb4f3 commit 325f953

File tree

6 files changed

+278
-225
lines changed

6 files changed

+278
-225
lines changed

examples/AntiAliasing/AntiAliasingComparison/AntiAliasingComparison.java

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ public class AntiAliasingComparison extends PApplet {
102102

103103
// AntiAliasing render targets
104104
PGraphics3D pg_render_noaa;
105+
PGraphics3D pg_render_msaa;
105106
PGraphics3D pg_render_smaa;
106107
PGraphics3D pg_render_fxaa;
107-
PGraphics3D pg_render_msaa;
108108
PGraphics3D pg_render_gbaa;
109109

110110
// toggling active AntiAliasing-Mode
@@ -122,8 +122,6 @@ enum SMAA_MODE{ EGDES, BLEND, FINAL }
122122
float gamma = 2.2f;
123123
float BACKGROUND_COLOR = 32;
124124

125-
// PShape shape;
126-
127125
DwMagnifier magnifier;
128126

129127

@@ -141,59 +139,26 @@ public void settings() {
141139
}
142140

143141

144-
145-
146142
public void setup() {
143+
surface.setResizable(true);
147144
surface.setLocation(viewport_x, viewport_y);
148145

146+
// projection
147+
perspective(60 * DEG_TO_RAD, width/(float)height, 2, 6000);
148+
149149
// camera
150150
peasycam = new PeasyCam(this, -4.083, -6.096, 7.000, 1300);
151-
peasycam.setRotations( 1.085, -0.477, 2.910);
151+
peasycam.setRotations(1.085, -0.477, 2.910);
152152

153-
// projection
154-
perspective(60 * DEG_TO_RAD, width/(float)height, 2, 6000);
155-
156153
// processing font
157154
font48 = createFont("../data/SourceCodePro-Regular.ttf", 48);
158155
font12 = createFont("../data/SourceCodePro-Regular.ttf", 12);
159156

160-
// load obj file into shape-object
161-
// shape = loadShape("examples/data/skylight_demo_scene.obj");
162-
// shape.scale(20);
163-
164-
165157
// main library context
166158
context = new DwPixelFlow(this);
167159
context.print();
168160
context.printGL();
169-
170-
// MSAA - main render-target for MSAA
171-
pg_render_msaa = (PGraphics3D) createGraphics(width, height, P3D);
172-
pg_render_msaa.smooth(8);
173-
pg_render_msaa.textureSampling(5);
174-
175-
// NOAA - main render-target for FXAA and MSAA
176-
pg_render_noaa = (PGraphics3D) createGraphics(width, height, P3D);
177-
pg_render_noaa.smooth(0);
178-
pg_render_noaa.textureSampling(5);
179-
180-
// FXAA
181-
pg_render_fxaa = (PGraphics3D) createGraphics(width, height, P3D);
182-
pg_render_fxaa.smooth(0);
183-
pg_render_fxaa.textureSampling(5);
184-
185-
// SMAA
186-
pg_render_smaa = (PGraphics3D) createGraphics(width, height, P3D);
187-
pg_render_smaa.smooth(0);
188-
pg_render_smaa.textureSampling(5);
189-
190-
// GBAA
191-
pg_render_gbaa = (PGraphics3D) createGraphics(width, height, P3D);
192-
pg_render_gbaa.smooth(0);
193-
pg_render_gbaa.textureSampling(5);
194-
195161

196-
197162
// callback for scene display (used in GBAA)
198163
DwSceneDisplay scene_display = new DwSceneDisplay() {
199164
@Override
@@ -207,17 +172,49 @@ public void display(PGraphics3D canvas) {
207172
smaa = new SMAA(context);
208173
gbaa = new GBAA(context, scene_display);
209174

210-
211-
int mag_h = (int) (height/2.5f);
212-
magnifier = new DwMagnifier(this, 4, 0, height-mag_h, mag_h, mag_h);
175+
// magnifier
176+
int mag_wh = (int) (height/2.5f);
177+
magnifier = new DwMagnifier(this, 4, 0, height-mag_wh, mag_wh, mag_wh);
213178

214179
frameRate(1000);
215180
}
216181

217-
218182

183+
// dynamically resize render-targets
184+
public boolean resizeScreen(){
219185

186+
boolean[] RESIZED = {false};
187+
188+
pg_render_noaa = DwGLTextureUtils.changeTextureSize(this, pg_render_noaa, width, height, 0, RESIZED);
189+
pg_render_msaa = DwGLTextureUtils.changeTextureSize(this, pg_render_msaa, width, height, 8, RESIZED);
190+
pg_render_fxaa = DwGLTextureUtils.changeTextureSize(this, pg_render_fxaa, width, height, 0, RESIZED);
191+
pg_render_smaa = DwGLTextureUtils.changeTextureSize(this, pg_render_smaa, width, height, 0, RESIZED);
192+
pg_render_gbaa = DwGLTextureUtils.changeTextureSize(this, pg_render_gbaa, width, height, 0, RESIZED);
193+
194+
if(RESIZED[0]){
195+
resetMatrix();
196+
camera();
197+
perspective(60 * DEG_TO_RAD, width/(float)height, 2, 6000);
198+
199+
float[] rot = peasycam.getRotations();
200+
float[] lat = peasycam.getLookAt();
201+
double dis = peasycam.getDistance();
202+
203+
peasycam.setActive(false); // unregister handler
204+
peasycam = new PeasyCam(this, lat[0], lat[1], lat[2], dis);
205+
peasycam.setRotations(rot[0], rot[1], rot[2]);
206+
}
207+
peasycam.feed();
208+
209+
return RESIZED[0];
210+
}
211+
212+
213+
220214
public void draw() {
215+
216+
resizeScreen();
217+
221218
if(aa_mode == AA_MODE.MSAA){
222219
displaySceneWrap(pg_render_msaa);
223220
// RGB gamma correction
@@ -257,11 +254,9 @@ public void draw() {
257254
case GBAA: display = pg_render_gbaa; break;
258255
}
259256

260-
261257
magnifier.apply(display, mouseX, mouseY);
262258
magnifier.displayTool();
263259

264-
265260
peasycam.beginHUD();
266261
{
267262
// display Anti Aliased result
@@ -271,7 +266,7 @@ public void draw() {
271266
blendMode(BLEND);
272267

273268
// display magnifer
274-
magnifier.display(this.g);
269+
magnifier.display(g, 0, height-magnifier.h);
275270

276271
// display AA name
277272
String mode = aa_mode.name();

examples/FlowFieldParticles/FlowFieldParticles_Attractors/FlowFieldParticles_Attractors.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515

1616
import java.util.Locale;
1717

18-
import com.jogamp.opengl.GL2ES2;
18+
import com.jogamp.opengl.GL2;
1919
import com.thomasdiewald.pixelflow.java.DwPixelFlow;
2020
import com.thomasdiewald.pixelflow.java.dwgl.DwGLSLProgram;
2121
import com.thomasdiewald.pixelflow.java.dwgl.DwGLTexture;
22+
import com.thomasdiewald.pixelflow.java.dwgl.DwGLTextureUtils;
2223
import com.thomasdiewald.pixelflow.java.flowfieldparticles.DwFlowFieldParticles;
2324
import com.thomasdiewald.pixelflow.java.imageprocessing.DwFlowField;
2425
import com.thomasdiewald.pixelflow.java.imageprocessing.filter.DwFilter;
@@ -148,28 +149,20 @@ public void setup(){
148149
}
149150

150151

151-
public void resizeScene(){
152-
153-
if(pg_canvas != null && width == pg_canvas.width && height == pg_canvas.height){
154-
return;
155-
}
156-
157-
pg_canvas = (PGraphics2D) createGraphics(width, height, P2D);
158-
pg_canvas.smooth(0);
159-
160-
pg_luminance = (PGraphics2D) createGraphics(width, height, P2D);
161-
pg_luminance.smooth(0);
162-
163-
pg_obstacles = (PGraphics2D) createGraphics(width, height, P2D);
164-
pg_obstacles.smooth(0);
165-
166-
pg_impulse = (PGraphics2D) createGraphics(width, height, P2D);
167-
pg_impulse.smooth(0);
152+
// dynamically resize if surface-size changes
153+
public boolean resizeScene(){
168154

169-
setParticleColor(2);
170-
}
171-
155+
boolean[] RESIZED = { false };
156+
pg_canvas = DwGLTextureUtils.changeTextureSize(this, pg_canvas , width, height, 0, RESIZED);
157+
pg_obstacles = DwGLTextureUtils.changeTextureSize(this, pg_obstacles , width, height, 0, RESIZED);
158+
pg_impulse = DwGLTextureUtils.changeTextureSize(this, pg_impulse , width, height, 0, RESIZED);
159+
pg_luminance = DwGLTextureUtils.changeTextureSize(this, pg_luminance , width, height, 0, RESIZED);
172160

161+
if(RESIZED[0]){
162+
setParticleColor(2);
163+
}
164+
return RESIZED[0];
165+
}
173166

174167

175168
//////////////////////////////////////////////////////////////////////////////
@@ -364,7 +357,7 @@ public void draw(){
364357

365358

366359
void info(){
367-
String txt_device = context.gl.glGetString(GL2ES2.GL_RENDERER).trim().split("/")[0];
360+
String txt_device = context.gl.glGetString(GL2.GL_RENDERER).trim().split("/")[0];
368361
String txt_app = getClass().getSimpleName();
369362
String txt_fps = String.format(Locale.ENGLISH, "[%s] [%s] [%d/%d] [%7.2f fps] [particles %,d] ",
370363
txt_app, txt_device,

examples/FlowFieldParticles/FlowFieldParticles_DevDemo/FlowFieldParticles_DevDemo.java

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -202,60 +202,40 @@ public void setup(){
202202

203203
createGUI();
204204

205+
textSize(12);
206+
205207
frameRate(1000);
206208
}
207209

208210

209211

210-
public void resizeScene(){
211-
212-
if(pg_canvas != null && width == pg_canvas.width && height == pg_canvas.height){
213-
return;
212+
// dynamically resize if surface-size changes
213+
public boolean resizeScene(){
214+
215+
boolean[] RESIZED = { false };
216+
pg_canvas = DwGLTextureUtils.changeTextureSize(this, pg_canvas , width, height, 0, RESIZED);
217+
pg_aa = DwGLTextureUtils.changeTextureSize(this, pg_aa , width, height, 0, RESIZED);
218+
pg_checker = DwGLTextureUtils.changeTextureSize(this, pg_checker , width, height, 0, RESIZED);
219+
pg_obstacles = DwGLTextureUtils.changeTextureSize(this, pg_obstacles , width, height, 0, RESIZED);
220+
pg_spheres = DwGLTextureUtils.changeTextureSize(this, pg_spheres , width, height, 0, RESIZED);
221+
pg_particles = DwGLTextureUtils.changeTextureSize(this, pg_particles , width, height, 0, RESIZED);
222+
pg_trails = DwGLTextureUtils.changeTextureSize(this, pg_trails , width, height, 0, RESIZED, GL3.GL_RGBA16F, GL3.GL_RGBA, GL3.GL_FLOAT);
223+
pg_trails_tmp = DwGLTextureUtils.changeTextureSize(this, pg_trails_tmp, width, height, 0, RESIZED, GL3.GL_RGBA16F, GL3.GL_RGBA, GL3.GL_FLOAT);
224+
pg_impulse = DwGLTextureUtils.changeTextureSize(this, pg_impulse , width, height, 0, RESIZED);
225+
pg_luminance = DwGLTextureUtils.changeTextureSize(this, pg_luminance , width, height, 0, RESIZED);
226+
pg_gravity = DwGLTextureUtils.changeTextureSize(this, pg_gravity , width, height, 0, RESIZED);
227+
228+
if(RESIZED[0]){
229+
pg_gravity.beginDraw();
230+
pg_gravity.blendMode(REPLACE);
231+
pg_gravity.background(0, 255, 0);
232+
pg_gravity.endDraw();
233+
234+
setParticleColor(PARTICLE_COLOR);
235+
setCheckerboardBG(BACKGROUND_MODE);
214236
}
215-
216-
pg_aa = (PGraphics2D) createGraphics(width, height, P2D);
217-
pg_aa.smooth(0);
218-
pg_aa.textureSampling(5);
219-
220-
pg_checker = (PGraphics2D) createGraphics(width, height, P2D);
221-
pg_checker.smooth(0);
222-
223-
pg_canvas = (PGraphics2D) createGraphics(width, height, P2D);
224-
pg_canvas.smooth(0);
225-
226-
pg_obstacles = (PGraphics2D) createGraphics(width, height, P2D);
227-
pg_obstacles.smooth(0);
228-
229-
pg_spheres = (PGraphics2D) createGraphics(width, height, P2D);
230-
pg_spheres.smooth(0);
231-
232-
pg_particles = (PGraphics2D) createGraphics(width, height, P2D);
233-
pg_particles.smooth(0);
234-
235-
pg_trails = (PGraphics2D) createGraphics(width, height, P2D);
236-
pg_trails.smooth(0);
237-
DwGLTextureUtils.changeTextureFormat(pg_trails, GL3.GL_RGBA16F, GL3.GL_RGBA, GL3.GL_FLOAT);
238-
239-
pg_trails_tmp = (PGraphics2D) createGraphics(width, height, P2D);
240-
pg_trails_tmp.smooth(0);
241-
DwGLTextureUtils.changeTextureFormat(pg_trails_tmp, GL3.GL_RGBA16F, GL3.GL_RGBA, GL3.GL_FLOAT);
242-
243-
pg_impulse = (PGraphics2D) createGraphics(width, height, P2D);
244-
pg_impulse.smooth(0);
245-
246-
pg_luminance = (PGraphics2D) createGraphics(width, height, P2D);
247-
pg_luminance.smooth(0);
248-
249-
pg_gravity = (PGraphics2D) createGraphics(width, height, P2D);
250-
pg_gravity.smooth(0);
251-
252-
pg_gravity.beginDraw();
253-
pg_gravity.blendMode(REPLACE);
254-
pg_gravity.background(0, 255, 0);
255-
pg_gravity.endDraw();
256-
257-
setParticleColor(PARTICLE_COLOR);
258-
setCheckerboardBG(BACKGROUND_MODE);
237+
238+
return RESIZED[0];
259239
}
260240

261241

@@ -821,6 +801,7 @@ public void keyReleased(){
821801
if(key == '4') setParticleColor(3);
822802
if(key == '5') setParticleColor(4);
823803
if(key == '6') setParticleColor(5);
804+
if(key == 'm') context.printGL_MemoryInfo();
824805

825806
if(key == 'h') toggleGUI();
826807
}

0 commit comments

Comments
 (0)