We are about to switch to a new forum software. Until then we have removed the registration on this forum.
PGraphics canvas;
void setup() {
size(400, 400, P3D);
canvas = createGraphics(400, 400, P3D);
String[] args = {"YourSketchNameHere"};
SecondApplet sa = new SecondApplet();
PApplet.runSketch(args, sa);
}
void draw() {
canvas.beginDraw();
canvas.background(127);
canvas.lights();
canvas.translate(width/2, height/2);
canvas.rotateX(frameCount * 0.01);
canvas.rotateY(frameCount * 0.01);
canvas.box(150);
canvas.endDraw();
image(canvas, 0, 0);
}
public class SecondApplet extends PApplet {
public void settings() {
size(200, 100,P3D);
}
public void draw() {
background(255);
fill(0);
ellipse(100, 50, 10, 10);
}
}
With that code I get "createGraphics() requires size to use P3D or P2D" (paraphrasing)
Or if I try to create an instance of a Syphon window, for example, I get null pointer.
What's the deal? My goal is to create a 2-window app with Syphon output from one window and a P5 control setup on the other.
Answers
Place line 4 in its own settings function.
Kf
Personally I'd be wary of using P2D/P3D in both PApplets - there's some dodgy resource clean up code in the OpenGL renderer that might cause crashes in some circumstances doing this.
https://Forum.Processing.org/two/discussion/26815/arraylist-concurrentmodificationexception#Item_2
If Processing 3's pre-processor spots any method called settings() anywhere inside a ".pde" file, it won't create its own settings() anymore behind the scenes. :-SS
It means that your 1st
size(400, 400, P3D);
is gonna stay inside setup() rather than being automatically moved into settings(): :-Shttps://Processing.org/reference/settings_.html
@GoToLoop - yes, there's definitely that as well! :-) What I'm thinking of is that they took my suggestion of extending WeakReference in PGraphicsOpenGL to handle resource cleanup, but ignored my complaint that there's one static list. It means that with two PApplets using OpenGL you can have one cleaning up the resources of the other - this may or may not be a problem on any particular system, driver, etc.