Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

toxiclibs - toxiclibsSupport, PGraphics, setGraphics() - trying to use off screen buffer

$
0
0

hello,

I am fairly new to Processing and in the early stages of learning Java.
Thank you for this excellent library - it was crucial to the first major piece of software that I have written (used for an installation a couple of weeks ago).
What I am trying to do is use an instance of PGraphics (called 'frame' in the code below) to draw to the off screen buffer and then save as a .png - for many reasons, but in this case to use transparency (drawing lines and shapes(triangles) on a transparent background).
As soon as I either specify 'frame' in the constructor: "gfx = new ToxiclibsSupport (this, frame);" or use setGraphics(): "gfx.setGraphics(frame);" I get a draft rendering of the drawing - just black lines on a white background, no images, no shapes - for both the off screen buffer and the display.
I have tried everything to the limits of my current knowledge and abilities including using the P2D renderer (specified in size() and in the createGraphics () for 'frame'). As soon as I remove 'frame' from the ToxiclibsSupport constructor or comment out setGraphics(), everything returns to normal, so clearly it is the addition of this PGraphics instance. I have included a very simplified example of my code.

Thank you for any help,

ToxiclibsSupport gfx;
PGraphics frame;


void setup () {

  frame = createGraphics (width, height);
  gfx = new ToxiclibsSupport(this, frame);
  //gfx.setGraphics(frame);

}


void draw () {

  frame.save (imageFileName + nf (frameCount++, 3) + ".png");

}



used in a function:


void drawTriangles () {

  frame.beginDraw();

  for (int i = 0 ; i < triangleList.size () ; i++ ) {
    if (triangleList.get(i).on) {
      noStroke();
      colorSelect(i);
      gfx.polygon2D(triangleList.get(i).triangle);
    } else {
      noFill();
      stroke(white);
      gfx.polygon2D(triangleList.get(i).triangle);
    }
  }

  frame.endDraw();
  image(frame,0,0);
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles