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.
IndexProgramming Questions & HelpSyntax Questions › Extending PGraphics
Page Index Toggle Pages: 1
Extending PGraphics (Read 929 times)
Extending PGraphics
Oct 6th, 2009, 12:29pm
 
Hey everyone.

Now I've tried for a while to create my own subclass of the PGraphics class, but it's not working. I've seen the documentation about the methods I need to call, but I can't figure out how to do it.

Can anyone post a small example that shows how to extend the PGraphics class to draw something in an off screen buffer?

Thanks...
Re: Extending PGraphics
Reply #1 - Oct 6th, 2009, 12:33pm
 
Are you sure you need to extend the class to do what you want?  PGraphics objects act as offscreen buffers by default...
PGraphics myOffscreenBuffer = createGraphics(width, height, P2D);
myOffscreenBuffer.line(30,20,70,40);
etc... -- Ben
Re: Extending PGraphics
Reply #2 - Oct 6th, 2009, 5:56pm
 
Right, absolutely -- and for offscreen OpenGL drawing, I've had lots of luck with GLGraphics.
http://users.design.ucla.edu/~acolubri/processing/glgraphics/home/

I can share some examples if you like. I'm still working on how to properly get an offscreen GLGraphics buffer routed through shaders (not just the textures themselves). But that would be a subject for a different forum.

In other words, what Ben said for 2D, and for 3D/GPU-accelerated, GLGraphics.
Re: Extending PGraphics
Reply #3 - Oct 7th, 2009, 10:49am
 
ben_hem wrote on Oct 6th, 2009, 12:33pm:
Are you sure you need to extend the class to do what you want


Thanks guys. I somehow didn't get any notifications even though I subscribed to the subject.

Well, I just wanted to extend the PGraphics class so I could do all of the drawing inside a specific class and not in the root file. So I would be able to create this:

Code:

class MyDrawing extends PGraphics
{
  MyDrawing()
  {
super();

this.beginDraw();
this.rect(30, 30, 40, 40);
this.endDraw();
  }
}


and then just be able to do this in the main file:

Code:

MyDrawing theDrawing = new MyDrawing();
image(MyDrawing, 0, 0);


Is that possible?
Re: Extending PGraphics
Reply #4 - Oct 7th, 2009, 12:52pm
 
Sure, but the myDrawing object is kind of redundant in that example, because your PGraphics object is already separate from your main Processing window.  In the Processing reference example for PGraphics, the only reason that line gets drawn is the last line:

 image(pg, 10, 10);

--Ben
Page Index Toggle Pages: 1