Hi, just got this figured out and thought I like to share it with the community.
This is for displaying the same animation in two separate processing windows, very useful if you want to have UI + preview showing on the first window, and just show the animation on the second window (full screen on extended desktop for projector output).
There are other ways to do this, but by copying the animation and display it using GLTexture you don't have to do an extensive setup like draw to offscreen GLbuffer, basically what you see is what you get. It can slow down your framerate, so I recommend copying every other (or third) frame. Be sure to install the glgraphics library.
Code:
private static secondCanvas sCanvas;
private static secondApplet sApplet;
import processing.opengl.*;
import codeanticode.glgraphics.*;
import java.awt.*;
import java.awt.event.*;
import processing.core.*;
GLTexture tex;
int xPos = 0;
int yPos = 0;
void setup() {
size(400, 400,GLConstants.GLGRAPHICS);
tex = new GLTexture(this,width,height);
sApplet = new secondApplet();
sCanvas = new secondCanvas("follower", sApplet, screen.width/2, screen.height/2);
}
void draw() {
background(0);
fill(200, 100, 0);
rect(mouseX,mouseY, 100, 100);
fill(100,200, 50);
ellipse(200,yPos++, 100, 100);
if(yPos >= height) yPos = 0;
PImage copyScreen = get();
tex.putImage(copyScreen);
}
//---------this sets up the second window--------------
public class secondApplet extends PApplet {
public void setup() {
size(100, 100);//---numbers doesn't seem matter, change size inside class secondCanvas
}
//---------this draws the second window--------------
public void draw() {
background(0);
image (tex,0,0,width,height);
}
}
public class secondCanvas extends Frame {
public secondCanvas(String name, PApplet embed, int x, int y) {
super(name);
// add the PApplet to the Frame
setLayout(new BorderLayout());
add(embed, BorderLayout.CENTER);
// ensures that the animation thread is started and
// that other internal variables are properly set.
embed.init();
// add an exit on close listener
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
// exit the application
System.exit(0);
}
}
);
setSize(400+16, 400+38);//--add the size of the window
setLocation(x, y);
setVisible(true);
}
}