We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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);
}
Answers
Dunno whether that's the problem, however frame is a field of class PApplet.
Maybe rename it to something else, like pg or whatever? :-??
I tried using 'fr' - no change.
Worth a try at least... However your posted code accesses unknown members, such as triangleList & colorSelect(). It helps a lot to post all the "actors" involved. :-\"
ok, here is revised code:
Sorry dunno much about toxiclibs. And got no idea what that class ToxiclibsSupport is! X_X
Seems like it's not compatible w/ Processing 3 either! :-<
Also I can't spot where triangleList was declared at? :-@
You can try out your luck here as well:
https://www.Reddit.com/r/processing/new/
And ultimately here:
https://BitBucket.org/postspectacular/toxiclibs/issues
ToxicLibs' site: http://ToxicLibs.org
This program uses toxiclibs extensively - eg. "gfx.polygon2D....." - everything works as it is supposed to until now - trying to use PGraphics with it.
http://toxiclibs.org/docs/p5/toxi/processing/ToxiclibsSupport.html#setGraphics(processing.core.PGraphics)
http://toxiclibs.org/docs/core/
triangle list has been declared:
ArrayList <TriangleList> triangleList = new ArrayList <TriangleList>();
http://www.creativeapplications.net/processing/working-with-toxiclibs-processing-tutorial
https://forum.processing.org/two/discussions/tagged/toxiclibs
Since your posted code isn't runnable, it doesn't even got the
import
statements after all, I've decided to take a look at the library by myself, and then come up w/ my own example. Here it is: :ar!totally works now - all I had to do was prepend the fill/noFill, stroke/noStroke functions with the fr object. Your example also provides some other insights (as always) into efficient Java coding. Many thanks GoToLoop excellent :)