Multiple windows - clone one to another with pgraphics obj

hi to all!
i want clone one windows into another:
if i use this 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");
  }
}

it works, but just if i don’t use opengl, P2D…can anyone help me to solve this problem?

1 Like

Simply put, no! :smile:

You can’t do this - the two windows have different OpenGL contexts. Only way would be to download the pixels into a Java2D PImage, int[], etc., or you could look at Syphon / Spout.

1 Like

Indeed we can transfer the contents of a PImage::pixels[] to another 1 via arrayCopy() and long as they’ve got same width & height. :money_mouth_face:

2 Likes

If you post your question to multiple sites, please link between those posts. This question has also been asked here:

https://stackoverflow.com/q/50794029/873165

1 Like

Here too: https://Forum.Processing.org/two/discussion/28051/multiple-window-clone-main-window

1 Like

thank you!! i solved using PImage as buffer

  img.pixels=pixels;
  win.display(img);

:slight_smile:

i know is me!! i also wrote there!

ok!! next time i will link it! :slight_smile: