Trouble exporting P3D via PGraphics recording (OpenGL error 1282) [SOLVED?]

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)


Note how the green background is missing, it draws fine without the export crash and exports fine on the standard renderer


int factor = 5;

void setup() {
  size(500, 500, P3D);
  PGraphics out = createGraphics(width * factor, height * factor, P3D);
  beginRecord(out);
  out.scale(factor);
  background(0, 100, 0);
  stroke(255);
  noFill();
  translate(250, 250, 0);
  box(200);
  endRecord();
  out.save("big_box.png");
}

PS: Could this be something that is more than 10 years old?

Hello,

beginRecord() / Reference / Processing.org states:

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.

:)

1 Like

WOW! That’s kind of shocking!

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 :confused:

Nice workaround! Another one would be to draw a coloured rect before everything else, I suppose…

1 Like

This sets background in sketch window:

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
  }

Sketch does not look good:

Recorded image is beautiful:

Open images to compare!

:)