PShapes in P2D

edited July 2016 in Library Questions


My sketch is setup to run under P2D: size(1920,1080,P2D);

I'm using beginRecord(PDF, etc) & endRecord(); to output a PDF from 1 single frame.

If I draw shapes dynamically they appear in the PDF no problem using beginShape(), vertex(), endShape().

However if I create a PShape object and create a shape that way (which is more efficient) then that shape does not appear in the PDF but does appear on screen.

I'm guessing this is something to do with the way the P2D OPENGL works, but just want to see if it's intended behaviour or a "bug".

Any insight to help me understand this better would be great.

(BTW, I realise there is also a PDF mode, but ideally I'd like a screen preview too?)





  • do you have a small runnable example showing the problem? otherwise we are guessing.

  • edited July 2016

    Yep, here's a quick test sketch.... interesting to know if this is "working as intended" or "not"... I'm running on Windows if that has any influence on the OpenGL rendering aspect...

    EDIT for clarity: 1) size(400, 400,P2D); = No Pshape in PDF 2) size(400, 400); = PShape in PDF

    import processing.pdf.*;
    boolean record;
    PShape s;
    void setup() {
      size(400, 400);
      s = createShape();
      s.fill(0, 0, 255);
      s.vertex(0, 0);
      s.vertex(0, 50);
      s.vertex(50, 50);
      s.vertex(50, 0);
    void draw() {
      if (record) {
        beginRecord(PDF, "frame-####.pdf"); 
      shape(s, mouseX, mouseY);
      if (record) {
        record = false;
    // Use a keypress so thousands of files aren't created
    void mousePressed() {
      record = true;
  • Answer ✓

    I think this is a bug? No reason why PShapes shouldn't appear in a PDF. @codeanticode would know for sure.

  • Thanks @shiffman ! Maybe I'll report it on GitHub.

Sign In or Register to comment.