Recording to a PGraphics with rendering mode set to P2D or P3D

Hi!

I am currently writing a class OffScreenRender that creates a new PGraphics and then records to it using the methods startRender() and stopRender()

When I create the class using render = parent.createGraphics(width, height); using the default render everything works as it should.

But when I try to use P2D or P3D render = parent.createGraphics(width, height, parent.P3D); I get an error: "OpenGL error 1282 at top endDraw(): invalid operation". Can anyone please help me why I get this error?

The error appears when running both external IDE (IntelliJ) and rewriting the class for the Processing IDE.

The full class can be seen below:

import processing.core.*;

/*
 * Renders the processingsketch to an external file at specified resolution.
 */

public class OffScreenRender
{
    PApplet parent; // The parent PApplet
    PGraphics render;
    int width;
    int height;
    int resFactor;
    int frameNumber;

    OffScreenRender(PApplet p, int width_, int height_, int resFactor_)
    {
        //Initialize variables
        parent = p;
        width = width_;
        height = height_;
        resFactor = resFactor_;

        render = parent.createGraphics(width, height, parent.P3D);
    }

    //Record the image
    void startRender()
    {
        parent.beginRecord(render);
        render.scale(resFactor);
    }

    //Stop the recording of the image
    void stopRender()
    {
        parent.endRecord();
        render.save("hej" + frameNumber + ".tif");
        PApplet.println("FRAME SAVED");
        frameNumber++;
    }
}
Tagged:

Answers

  • Well, for one, all calls to a PGraphics should be between beginDraw() and endDraw().

    See: http://www.processing.org/reference/PGraphics.html

    Not seeing either in your code example.

  • Thank you for your answer! I see that, so my problem is that you cannot record to a PGraphics set to any other renderer than the default (JAVA2D) or PDF?

    The reason for using beginRecord instead of BeginDraw is that it echoes all drawing statements to the PGraphics as well as to the display window.

  • Answer ✓

    Just rewrite your drawing calls to work on a PGraphics, then you won't have to rely on unstable hacks plus you will be able to use any type of PGraphics of any size (including g which is the main PGraphics).

  • edited March 2014

    Sounds like a plan! And thank you for answering me! I will certainly try to work like you suggested instead.

    But still this must be a bug? The beginRecord() should be able to handle to record to a PGraphics with an OpenGL renderer. Adding the beginDraw() and endDraw() does not affect the outcome, it still crashes with OpenGL error 1282 at top endDraw(): invalid operation as an error message.

  • Answer ✓

    Try calling save before calling endRecord().

  • That worked! Thank you!

Sign In or Register to comment.