We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProcessing DevelopmentCore,  Processing Development Environment (PDE) › New PGraphics object for offscreen rendering
Page Index Toggle Pages: 1
New PGraphics object for offscreen rendering (Read 3923 times)
New PGraphics object for offscreen rendering
Jul 23rd, 2007, 6:19pm
 
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
Re: New PGraphics object for offscreen rendering
Reply #1 - Jul 26th, 2007, 10:43pm
 
sounds fun. i don't think we're going to add much to the processing core libraries anytime soon, we're trying to keep things simple and get the bugs fixed.

that said, this is the reason why size() is made to take other renderers. you can package your code as a library, and then use:

size(400, 400, "some.package.YourRendererHere");

and that will make use of your renderer. same syntax for createGraphics(). so with that, just give it a name like "OffscreenGL" instead of using the PGraphics prefix, since we want to keep that for core libraries only.
Re: New PGraphics object for offscreen rendering
Reply #2 - Jul 30th, 2007, 5:50pm
 
Hey fry,

Thanks for your reply!

I'll read the documentation (nooo!) and go ahead to properly package this code as a library.

ac

Pd: One application of this offscreen rendering class was to have the image composed with processing deformed to compensate the distortions introduced by projecting on the floor by a wall-mounted projector... I have a couple of interactive games with motion tracking that make use of this. Once I'm done polishing a couple of details, I'll post them in the Exhibition section


Re: New PGraphics object for offscreen rendering
Reply #3 - Aug 12th, 2007, 4:24pm
 
I wanted to play with your code for this, but alas after some investigating I realize Mobility Radeon 9000 lacks framebuffer and pixelshader extensions.
Re: New PGraphics object for offscreen rendering
Reply #4 - Aug 15th, 2007, 6:55pm
 
ugh! I thought that this chip would have supported at least framebuffer object extensions... but unfortunately seems that you are right.

FBO support is available in the R300 and newer ATI GPUs, meaning that you need at least a Radeon 9500 to have offscreen rendering through FBOs.

On the other hand, there is another openGL extension, pBuffers, which is supported by the R200 chips:
http://www.delphi3d.net/hardware/extsupport.php?extension=WGL_ARB_pbuffer

Offscreen rendering could be implemented through pBuffers instead of FBOs on older chips.
The problem of pBuffers, though, is that they are much more cumbersome to implement and also are platform dependent (as far as I know)...
Page Index Toggle Pages: 1