second monitor window (and optimizing performance)
in
Programming Questions
•
2 years ago
Hi, I'm trying to make a copy of a applet window to use as a videomonitor, aside from the main applet that's being projected and not visible to me. I've succeeded to do this, but I have a feeling there's a better way of doing this (performance-wise).
I've found some info here and there on how to make a second appletwindow. But it's not really clear to me what's the most clever way to draw the same thing to both applets. Currently I'm drawing everything to the first one and copying the pixeldata to the second one like this:
I'm noticing that it is a lot harder on the computer than when I'm drawing on only one applet, which makes perfect sense because I'm reading every pixel and writing it again, which seems redundant.
Would it be a good idea to draw to an off-screen PGraphics buffer first and then drawing that buffer on both applets with image()? Or is there a way to access the graphics buffer of the main applet and draw that into the second applet?
Any suggestions much appreciated.
Martijn
I've found some info here and there on how to make a second appletwindow. But it's not really clear to me what's the most clever way to draw the same thing to both applets. Currently I'm drawing everything to the first one and copying the pixeldata to the second one like this:
- secondApplet mApplet;
- void draw() {
- //drawing stuff here
- loadPixels();
- mApplet.loadPixels();
- arrayCopy(pixels,mApplet.pixels);
- mApplet.updatePixels();
- mApplet.redraw();
- }
- //here's the applet stuff, in setup() I instantiate it with new PFrame();
- public class PFrame extends Frame {
public PFrame() {
setBounds(10,10,640,480);
mApplet = new secondApplet();
add(mApplet);
mApplet.init();
//show();
setVisible(true);
}
}
public class secondApplet extends PApplet {
public void setup() {
size(640, 480);
background(0);
noLoop();
}
public void draw() {
}
}
I'm noticing that it is a lot harder on the computer than when I'm drawing on only one applet, which makes perfect sense because I'm reading every pixel and writing it again, which seems redundant.
Would it be a good idea to draw to an off-screen PGraphics buffer first and then drawing that buffer on both applets with image()? Or is there a way to access the graphics buffer of the main applet and draw that into the second applet?
Any suggestions much appreciated.
Martijn
2