We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Show same animation in two applet window hack
Page Index Toggle Pages: 1
Show same animation in two applet window hack (Read 1046 times)
Show same animation in two applet window hack
Mar 4th, 2010, 10:49am
 
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);
 }
}
Re: Show same animation in two applet window hack
Reply #1 - Mar 4th, 2010, 11:03am
 
I had to add the window boarder size to the second window to keep two windows the same size. see this line:

   setSize(400+16, 400+38);//--add the size of the window

is there a way to disable the window frame in the second applet window? I tried using frame.setUndecorated(true) but it only removes the main window frame.
Re: Show same animation in two applet window hack
Reply #2 - Mar 4th, 2010, 12:33pm
 
Perhaps secondCanvas.setUndecorated(true) instead?
Re: Show same animation in two applet window hack
Reply #3 - Mar 5th, 2010, 1:36pm
 
PhiLho  wrote on Mar 4th, 2010, 12:33pm:
Perhaps secondCanvas.setUndecorated(true) instead

ok got this bit figured out, add just setUndecorated(true) to the Frame part of the secondCanvas to not show the window frame.

Code:
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();
   setUndecorated(true);//--removes window frame
 
   // add an exit on close listener
   addWindowListener(new WindowAdapter() {
     public void windowClosing(WindowEvent evt) {
       // exit the application
       System.exit(0);
     }
   }
   );

   setSize(stageWidth, stageHeight);//--add the size of the window
   setLocation(x, y);
   setVisible(true);
 }
}
Re: Show same animation in two applet window hack
Reply #4 - Mar 5th, 2010, 1:53pm
 
I been tinkering with this method and tried to port my visualSynth processing app into this new setup, this is what i found.

I had a hard time moving the UI stuff into the secondCanvas... it kept giving errors as I'm guessing the environment is not the same, for instance I can't invoke glgraphics environment in both canvas.

The secondCanvas natively is running as JAVA2D, what i end up doing is draw my animation, copy animation for display on secondCanvas, then draw my UI on top. Note, when resizing this image on secondCanvas, it start to drop frames but if I display exact size of image as it was copied, then the lag is minimal. My main UI environment is setup at 1024x768 so for now I'm stuck in this resolution.
Page Index Toggle Pages: 1