Does exist an equivalent Processing's PGraphics on OF?

Is possible to create various canvas and select them using a keyCode?
I’m planning to organize animations in classes, that will start to run when them be triggered.

As processing developer I do it creating various classes that have draw and setup functions, but I use an PGraphics Class to draw only on their Applets.

So in method draw I used to do this:

image(PGraphics canvas1,0,0);

1 Like

I believe the closest thing to PGraphics is ofFBO (link). In your case, each class could have its own ofFBO that you can render to and then display when you like. ofFBO is essentially a texture and can be treated much like an ofTexture (you can display it on screen, use it with shaders, etc).

In processing:

PGraphics pg;

void setup() {
  size(100, 100);
  pg = createGraphics(40, 40);
}

void draw() {
  pg.beginDraw();
  pg.background(100);
  pg.stroke(255);
  pg.line(20, 20, mouseX, mouseY);
  pg.endDraw();
  image(pg, 9, 30); 
  image(pg, 51, 30);
}

In openFrameworks:


ofFbo fbo;

void setup() {
  fbo.allocate(40, 40, GL_RGBA); 
}

void draw() {
  fbo.begin();
  ofBackground(100);
  ofNoFill(0);
  ofSetColor(255);
  ofLine(20, 20, mouseX, mouseY);
  fbo.end();

  ofFill();
  ofSetColor(255);
  
  fbo.draw(9, 30);
  fbo.draw(51, 30);
}
3 Likes

Thank you for the thorough reply bakercp!

1 Like