Hi,
Lately I've been playing around with processing and glsl shaders. It would be useful to have offscreen rendering through the OpenGL's FBO (Framebuffer Object) extension, but as nicely integrated into Processing as possible. A while ago a wrote some sketches having FBO's and rendering to texture capabilities, however I couldn't use any of the processing routines anymore because I was working in "pure" opengl mode.
So I went ahead and I created a new PGraphics object called PGraphicsOffscreenGL, where the internal GLCanvas is replaced by a GLPBuffer, which handles all the offscreen rendering.
I know that it is already possible to do offscreen rendering using a regular PGraphics object:
Code:
PGraphics pg;
pg = createGraphics(640, 480, P3D);
...
pg.beginDraw();
...
pg.ellipse(mouseX, mouseY, 10, 10);
...
pg.endDraw();
...
However, I'm interested in using the image stored by the pg object to texture a quad and then applying some shaders to it:
Code:
...
// shader binding code would go in here...
...
beginShape(QUADS);
texture(pg);
vertex(0, 0, 0, 0, 0);
vertex(width, 0, 0, pg.width, 0);
vertex(width, height, pg.width, pg.height);
vertex(0, height, 0, 0, pg.height);
endShape();
...
Even though this method works, it's very slow for resolutions above 320x240, and the reason seems to be the texture copy from the pg object into an opengl texture.
This is why I thought that it would be useful to have a PGraphicsOffscreenGL class that automatically renders to a texture. I just finished writing two examples, one with the regular PGraphics method, and the other using the new class:
http://shaders.computaciongrafica.com/processing/offscreenTest.applets/pgraphics.html
http://shaders.computaciongrafica.com/processing/offscreenTest.applets/pgraphicsGL.html
And the later is much, much faster (as expected), the speed-up is around 10x.
This code is just a proof of concept, I basically hacked the original PGraphicsOpenGL object from the processing source code, and then I added it as a additional file in the pgraphicsGL example.
There are things that don't work, for example, image loading.
I just wanted to know what do you think of adding this class to the processing core (perphaps something similar is already planned for future releases of processing). Suggestions and comments are welcomed.
And one final question... in the case I want to recompile the opengl.jar adding PGraphicsOffscreenGL to it... what are the steps I should follow? (I don't have much experience with java development)
Thanks
AC