Using PGraphics class in Java without instantiating PApplet class

Hello,

I'd like to use PGraphics in a JavaFX Application, which means my Main-Class cannot extend from PApplet. Is there any example or any chance at all to make usage of PGraphics without instantiating the PApplet-Class? I also tried to runn the PApplet from another class, but it was a mess which didnt seem to work at all.

Thank you

Answers

  • If you read the javadoc they specify that it may be unsafe to create a PGraphics object using any method other than createGraphics().

  • edited January 2017 Answer ✓

    As long as JAVA2D renderer is enough for you, apparently PGraphicsJava2D can be used standalone w/o depending on PApplet. :-bd The other renderers crashed on me though. b-(

    https://forum.Processing.org/two/discussions/tagged/pgraphicsjava2d

    // forum.Processing.org/two/discussion/20482/
    // using-pgraphics-class-in-java-without-instantiating-papplet-class
    
    // GoToLoop (2017-Jan-26)
    
    import processing.core.PGraphics;
    import processing.awt.PGraphicsJava2D;
    
    size(500, 400);
    noLoop();
    background(0);
    
    PGraphics pg = new PGraphicsJava2D();
    pg.setSize(300, 200);
    
    pg.beginDraw();
    pg.background(0xff008000);
    pg.fill(0xffFF0000);
    pg.stroke(0);
    pg.strokeWeight(1.5f);
    pg.rect(pg.width>>2, pg.height>>2, pg.width>>1, pg.height>>1);
    pg.endDraw();
    
    image(pg, width - pg.width >> 1, height - pg.height >> 1);
    
Sign In or Register to comment.