The filer(PShader) function should work with a PGraphics surface, as long as it is created as P2D or P3D:
- PShader edges;
- boolean applyFilter = true;
- PGraphics pg;
- void setup() {
- size(640, 360, P3D);
- edges = loadShader("edges.glsl");
- pg = createGraphics(640, 360, P3D);
- noStroke();
- }
- void draw() {
- pg.beginDraw();
- pg.noStroke();
- pg.background(0);
- pg.lights();
- pg.translate(width/2, height/2);
- pg.pushMatrix();
- pg.rotateX(frameCount * 0.01);
- pg.rotateY(frameCount * 0.01);
- pg.box(120);
- pg.popMatrix();
- if (applyFilter == true) {
- pg.filter(edges);
- }
- // The sphere doesn't have the edge detection applied
- // on it because it is drawn after filter() is called.
- pg.rotateY(frameCount * 0.02);
- pg.translate(150, 0);
- pg.sphere(40);
- pg.endDraw();
- image(pg, 0, 0, width, height);
- }
- void mousePressed() {
- applyFilter = !applyFilter;
- }