Render PGraphics2D without PApplet off screen

I'd like to use Processing in an existing project alongside what I've already written and not be confined to running everything within a PApplet.

I can render whatever I want off screen using the software renderer PGraphicsJava2D class.

PGraphicsJava2D pGraphics = new PGraphicsJava2D(); pGraphics.init(500, 500, PGraphics.RGB); pGraphics.beginDraw(); pGraphics.rect(10, 10, 100, 100); pGraphics.endDraw();

I can get a BufferedImage from pGraphics and save it to my disk to that it works.

ImageIO.write((BufferedImage) pGraphics.get().getNative(), "jpg", new File("image.jpg"));

I'd like to be able to render this with JOGL, however, when instantiating PGraphics2D a NullPointerException is thrown.

PGraphics2D pGraphics = new PGraphics2D(); pGraphics.init(500, 500, PGraphics.RGB); pGraphics.beginDraw(); pGraphics.rect(10, 10, 100, 100); pGraphics.endDraw();

java.lang.NullPointerException at processing.opengl.PGraphicsOpenGL.getPrimaryPGL(PGraphicsOpenGL.java:1557) at processing.opengl.PGraphicsOpenGL.beginDraw(PGraphicsOpenGL.java:1464) at processing.opengl.PGraphicsOpenGL$beginDraw.call(Unknown Source)

Sign In or Register to comment.