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

**URL:** https://discourse.processing.org/t/trouble-exporting-p3d-via-pgraphics-recording-opengl-error-1282-solved/47033
**Category:** Processing
**Created:** [August 27, 2025, 2:37pm UTC](https://discourse.processing.org/t/trouble-exporting-p3d-via-pgraphics-recording-opengl-error-1282-solved/47033 "2025-08-27T14:37:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)
#### Post date: [August 27, 2025, 2:37pm UTC](https://discourse.processing.org/t/trouble-exporting-p3d-via-pgraphics-recording-opengl-error-1282-solved/47033/1 "2025-08-27T14:37:34Z")

</div>

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)

> ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/b/3/b34a4250e682eba983495187c1ea9d4b9ed201d4.png)  
> Note how the green background is missing, it draws fine without the export crash and exports fine on the standard renderer

```pde

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?

- [OpenGL error 1282 at top endDraw(): invalid operation - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/3155/opengl-error-1282-at-top-enddraw-invalid-operation)
- [opengl error · Issue #2372 · processing/processing · GitHub](https://github.com/processing/processing/issues/2372)

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [August 27, 2025, 6:55pm UTC](https://discourse.processing.org/t/trouble-exporting-p3d-via-pgraphics-recording-opengl-error-1282-solved/47033/2 "2025-08-27T18:55:24Z")

</div>

Hello,

[beginRecord() / Reference / Processing.org](https://processing.org/reference/beginRecord_.html) states:

**beginRecord()** works only with the PDF and SVG renderers.

It does work with P3D:

> [@villares](#):
>
> 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…

And same issue with no background change.

Still exploring!

A workaround:

```auto
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.

`:)`

---

<div class="post-metadata">

### Author: ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)
#### Post date: [August 27, 2025, 8:22pm UTC](https://discourse.processing.org/t/trouble-exporting-p3d-via-pgraphics-recording-opengl-error-1282-solved/47033/3 "2025-08-27T20:22:04Z")

</div>

> [@glv](#):
>
> [beginRecord() / Reference / Processing.org](https://processing.org/reference/beginRecord_.html) states:
> 
> **beginRecord()** works only with the PDF and SVG renderers.

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 😕

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

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [August 27, 2025, 10:00pm UTC](https://discourse.processing.org/t/trouble-exporting-p3d-via-pgraphics-recording-opengl-error-1282-solved/47033/4 "2025-08-27T22:00:27Z")

</div>

This sets background in sketch window:

```auto
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 window does not look good:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/2/4/2429999ee4334b22505b19482b5308630f953272.png)

Recorded image is beautiful:

 ![big_box](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/e/6e6d41568e76fecb157c4fb2c073b59abb595456.png)

Open images to compare!

`:)`
