/** * this sketch shows how to hack a processing sketch so that it * is rendered into a FBO. the FBO can than be used as a texture * without any extra pixel copying costs. * that s the beauty of it. * * there is an issue with the framebuffer objects being larger * than the actual frame. */ import gestalt.Gestalt; import gestalt.candidates.rendertotexture.JoglTexCreatorFBO_DepthRGBA; import gestalt.p5.GestaltPlugIn; import gestalt.p5.JoglProcessingFrameBufferObject; import gestalt.shape.Plane; import processing.opengl.*; GestaltPlugIn gestalt; JoglProcessingFrameBufferObject _myFBO; Plane _myPlane; static final boolean USE_FBO = true; void setup() { /* setup p5 */ size(512, 512, OPENGL); rectMode(CENTER); /* by not create the p5 framebuffer object the sketch will run as a regular processing sketch */ if (USE_FBO) { /* create gestalt plugin. don t make it processing friendly */ gestalt = new GestaltPlugIn(this, false); gestalt.displaycapabilities().backgroundcolor.set(0.2f); /* this flag must be true if sketch is run in presentation mode */ JoglProcessingFrameBufferObject.PRESENTATION_MODE = false; /* create p5 framebuffer object. the first two values define the size of the actual frame the sketch will run in. */ _myFBO = new JoglProcessingFrameBufferObject(1024, 768, new JoglTexCreatorFBO_DepthRGBA(), gestalt, this); /* create plane to show processing sketch */ _myPlane = gestalt.drawablefactory().plane(); _myPlane.material().addPlugin(_myFBO); _myPlane.setPlaneSizeToTextureSize(); gestalt.bin(Gestalt.BIN_3D).add(_myPlane); } } void draw() { /* clear screen */ background(127, 255, 0); /* draw processing stuff */ fill(255); stroke(0); strokeWeight(20); rect(mouseX, mouseY, 200, 200); /* rotate plane with sketch */ if (USE_FBO) { _myPlane.rotation().x += 0.005f; _myPlane.rotation().y += 0.0033f; } }