Can there exist multiple pairs of beginDraw() and endDraw() invoked on the same PGraphics in the same frame?
Yes
Example code that worked with P2D:
Code
PGraphics a;
PGraphics b;
char c;
void setup()
{
size(600, 200, P2D);
a = createGraphics(180, 180, P2D);
b = createGraphics(180, 180, P2D);
a.beginDraw();
//a.background(255, 0, 0); // Set initial background
a.textAlign(CENTER, CENTER);
a.textSize(96);
c = 'A';
a.endDraw();
b.beginDraw();
//b.background(0, 255, 0); // Set initial background
b.endDraw();
imageMode(CENTER);
noLoop();
}
void draw()
{
// Set background and paint over
a.beginDraw();
a.background(155, 128, 0); // Set background to pain over
//a.clear();
a.text(c, a.width/3, a.height/2);
a.endDraw();
image(a, width/6, height/2);
c++;
// Adds to above
a.beginDraw();
a.text(c, 2*a.width/3, a.width/2);
a.endDraw();
c++;
if(c>'A' + 25) c = 'A';
image(a, 3*width/6, height/2);
// Display image
b.beginDraw();
b.image(a, 0, 0);
b.endDraw();
image(b, 5*width/6, height/2);
noLoop();
}
void keyPressed()
{
loop();
}
I had initial issues without P2D and worked directly with P2D.
Advance frames with a key press.
References:
:)