We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi!
I have a sketch that needs different render modes depending on different tasks. Is there a way to change the rendermode without restarting the sketch? I did this quick test below with a bad result. I got this error:
processing.corePApplet$RendererChangeException
void setup() {
size(300, 300, P2D);
background(233, 23, 23);
}
void draw() {
fill(255, 0, 0);
rect(100, 100, 100, 100);
fill(0, 255, 0);
rect(50, 50, 100, 100);
}
void keyPressed() {
if (key == '1') {
size(255, 255);
}
if (key == '2') {
size(255, 255, P2D);
}
if (key == '3') {
size(255, 255, P3D);
}
}
Are there any other way?
Answers
You're gonna need another PApplet instance in order to have more than 1 renderer.
Take a look at my examples in this thread post:
http://forum.processing.org/two/discussion/7202/controlp5-controlwindow-and-controlp5frame
However be aware that only 1 of those instances can use an OpenGL renderer like P2D & P3D!
On the other hand, we can have as many JAVA2D renderers as we wish! :-bd
And as a last touch, we can issue frame.setVisible(false/true) to hide or show the window.
Ok. Two stupid questions:
1) PApplet = the core in processing. Its the java class that processing is built upon?
2) But if I extends the PApplet - I need to switch into another window. Than the sketch will be even more heavy to run ... I need to use P2D cause making my sketch more smooth but if I need to switch between different windows it might be the same result. Or did I misunderstand?
Yup! It's the core of Processing's API framework. You can see the whole thing below:
https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java
frame.setVisible(false);
there.