Something I often do to export higher resolution images is to instantiate a big PGraphics object and then use beginRecord, endRecord and add scaling to the offscreen canvas. It still works fine for 2D, but it seems like on the P3D renderer something broke (or maybe I got something wrong?). Can anyone please help me figure this out?
I get OpenGL error 1282 at top endDraw(): invalid operation is it a known issue?
UPDATE: It looks like the proper way is to use out.save(...) before endRecord() I think I never seen mention to it on the docs… well…
(The background is saved but not seen on screen which is a bit weird, and if you add a background call before the recording it has no effect… weirder still)
beginRecord() works only with the PDF and SVG renderers.
It does work with P3D:
And same issue with no background change.
Still exploring!
A workaround:
int factor = 2;
PGraphics out;
void setup()
{
size(500, 500, P3D);
out = createGraphics(width * factor, height * factor, P3D);
out.beginDraw();
out.scale(factor);
out.background(0, 100, 0);
out.stroke(255);
out.noFill();
out.translate(250, 250, 0);
out.box(200);
out.endDraw();
out.save("big_box.png");
noLoop();
}
void draw()
{
// Keep in mind that out was scaled up and then back down:
image(out, 0, 0, width, height); // This scales down the output to fit in sketch window
}
Workaround not requested but posted for visitors to topic.
It would have to be modified for multiple frames.
Also, beginRecord()/endRecord()does not work with PDF and SVG if you are using P3D, you have to use beginRaw()/ endRaw() but the results are not very good: the ordering of the shapes gets recorded wrong and you see edges you shouldn’t see
Nice workaround! Another one would be to draw a coloured rect before everything else, I suppose…
int factor = 5;
void setup()
{
size(500, 500, P3D);
PGraphics out = createGraphics(width * factor, height * factor, P3D);
beginRecord(out); // This command tells Processing to "record" to the 'out' PGraphics object
// All drawing commands must now be directed to 'out'
g.background(0, 100, 0); // This works!
out.scale(factor);
stroke(255);
noFill();
translate(width/2, height/2);
rotateX(TAU/8);
rotateY(TAU/8);
box(200);
out.save("big_box.png");
endRecord(); // This ends the recording session
}