Hello. Im trying to do a preview output of main buffer Graphic in a extra pApplet.
Here my code:
layerWindow p;
LayerManager layer;
void settings(){
size(1280, 720, P3D);
}
void setup(){
p = new layerWindow();
layer = new LayerManager();
}
void draw(){
}
class LayerManager {
ArrayList<PGraphics>layers;
LayerManager() {
layers = new ArrayList<PGraphics>();
layers.add(createGraphics(width, height, P3D));
}
void update(PApplet p) {
layers.get(0).beginDraw();
//buffer.clear();
//buffer.shader(vs.get(0).shader);
//layers.get(0).hint(DISABLE_DEPTH_TEST);
layers.get(0).hint(DISABLE_OPTIMIZED_STROKE);
layers.get(0).hint(DISABLE_DEPTH_MASK);
layers.get(0).sphere(100);
layers.get(0).endDraw();
tint(255, 50);
image(layers.get(0), 0, 0);
}
}
public class layerWindow extends PApplet {
layerWindow() {
super();
PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
}
void settings() {
size(1280, 720, P2D);
}
void setup() {
}
void draw() {
layer.update(this);
}
}
but it return the following error:
You are trying to draw outside OpenGL’s animation thread.
Place all drawing commands in the draw() function, or inside
your own functions as long as they are called from draw(),
but not in event handling functions such as keyPressed()
or mousePressed().
How can i draw a PGraphic image in a extra Applet? Thanks!