multiple window - clone main window

hi to all!

i use processing as my principal instrument to do visual live set, and i've the necessity to clone the main window to another to control what is rendering in that moment!

for now i'm using this code:

class PWindow extends PApplet {
  PWindow() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
  }

  void settings() {
    size(500, 200);
  }

  void setup() {
    background(150);
  }

  void draw() {
    //here i want to clone the main window
  }

  void mousePressed() {
    println("mousePressed in secondary window");
  }
}


PWindow win;

public void settings() {
  size(320, 240);
}

void setup() { 
  win = new PWindow();
}

void draw() {
  background(255, 0, 0);
  fill(255);
  rect(10, 10, frameCount, 10);
}

void mousePressed() {
  println("mousePressed in primary window");
}  

is possible do what i ask starting with this?

thank to everyone!!

Answers

  • edited June 2018

    i try to use a PGraphi but it not clone the main window, any suggestion?

    PWindow win;
    PGraphics pg;
    
    public void settings() {
      size(320, 240);
    }
    
    void setup() { 
      win = new PWindow();
      pg = createGraphics(width, height);
    }
    
    void draw() {
      pg.beginDraw();
      pg.background(255, 0, 0);
      pg.fill(255);
      pg.rect(10, 10, frameCount, 10);
      win.draw(pg);
      pg.endDraw();
      image(pg, 0, 0);
      //win.draw();
    }
    
    void mousePressed() {
      println("mousePressed in primary window");
    }
    class PWindow extends PApplet {
      PWindow() {
        super();
        PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
      }
    
      void settings() {
        size(500, 200);
      }
    
      void setup() {
        background(150);
      }
    
      void draw(PGraphics pg) {
        image(pg, 0, 0, width, height);
      }
    
      void mousePressed() {
        println("mousePressed in secondary window");
      }
    }
    
  • Answer ✓

    solved, if someone is interested, here the code:

    PWindow win;
    PGraphics pg;
    
    public void settings() {
      size(640, 480);
    }
    
    void setup() { 
      win = new PWindow();
      pg = createGraphics(width, height);
      println(width, height);
    }
    
    void draw() {
      pg.beginDraw();
      pg.background(255, 0, 0);
      pg.fill(255);
      pg.rect(10, 10, abs(sin(frameCount*.02)*width), 10);
      pg.endDraw();
      image(pg, 0, 0, width, height);
      win.setPG(pg);
    }
    
    void mousePressed() {
      println("mousePressed in primary window");
    }  
    
    class PWindow extends PApplet {
      PGraphics pg1;
    
      PWindow() {
        super();
        PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
      }
    
      void settings() {
        size(320, 240);
      }
    
      void setup() {
        background(150);
        pg1 = createGraphics(width, height);
        println(width, height);
      }
    
      void setPG(PGraphics pg1) {
        pg1.beginDraw();
        this.pg1=pg1;
        pg1.endDraw();
      }
    
      void draw() {
        image(pg1, 0, 0, width, height);
      }
    
      void mousePressed() {
        println("mousePressed in secondary window");
      }
    }
    
  • i noticed that if i use P2D, it doesn't work!! and it give me this warning:

    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(). OpenGL error 1282 at top endDraw(): invalid operation

    can anyone tell me if there is a solution for this?

  • Please note that there’s a new forum

  • thank you! i post it into new forum! )

Sign In or Register to comment.