hi, you can find gui libraries that allow you to add separate windows to your sketch, there is g4p and controlP5. I am more familiar with the latter one.
here some sample code which adds a separate ControlWindow to your sketch and removes the frame decoration from your main sketch. With frame.setLocation (or the toggle 'toggleWindow') you can move the window between one and the other screen. if your presentation screen is set to 1024x768, your sketch should match this resolution. you can fetch a controlP5 copy from
here.
- import controlP5.*;
- import processing.opengl.*;
- ControlP5 cp5;
- void setup() {
- size(1024,768,OPENGL);
- frameRate(30);
- cp5 = new ControlP5(this);
- // create a new ControlWindow
- ControlWindow cw = cp5.addControlWindow("controlP5window",10,10,200,400,30);
- // add some controllers
- for(int i=0;i<10;i++) {
- Slider s = cp5.addSlider("s"+i,0,255,20,40 +i*15,100,10);
- s.setWindow(cw);
- }
- Toggle t = cp5.addToggle("toggleWindow",false,20,240,100,20);
- t.setWindow(cw);
- }
- void draw() {
- background(0);
- }
- // called by toggle 'toggleWindow'
- void toggleWindow(boolean theValue) {
- if(theValue) {
- frame.setLocation(screenWidth,0);
- } else {
- frame.setLocation(240,10);
- }
- }
- void controlEvent(ControlEvent theEvent) {
- println("got an event from "+theEvent.controller());
- }
- void keyPressed() {
- if(key=='1') {
- frame.setLocation(240,10);
- } else if(key=='2') {
- frame.setLocation(screenWidth,0);
- }
- }
- // overrides the init() method so we can undecorate the
- // main window first, then we have to call init() for the super class
- // to init the sketch
- public void init() {
- frame.removeNotify();
- frame.setUndecorated(true);
- frame.addNotify();
- super.init();
- }
other alternatives to look into are the NApplet library and the fullscreen library