# Multiple windows - clone one to another with pgraphics obj

**URL:** <https://discourse.processing.org/t/multiple-windows-clone-one-to-another-with-pgraphics-obj/869>\
**Category:** Coding Questions\
**Created:** [June 11, 2018, 1:16pm UTC](https://discourse.processing.org/t/multiple-windows-clone-one-to-another-with-pgraphics-obj/869 "2018-06-11T13:16:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bitCrasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bitcrasher/32/408_2.png) [@bitCrasher](https://discourse.processing.org/u/bitCrasher)\
**Post date:** [June 11, 2018, 1:16pm UTC](https://discourse.processing.org/t/multiple-windows-clone-one-to-another-with-pgraphics-obj/869/1 "2018-06-11T13:16:32Z")

</div>

hi to all!  
i want clone one windows into another:  
if i use this code:

```auto
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?

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [June 11, 2018, 3:46pm UTC](https://discourse.processing.org/t/multiple-windows-clone-one-to-another-with-pgraphics-obj/869/2 "2018-06-11T15:46:22Z")

</div>

Simply put, no! 😄

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.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 11, 2018, 3:53pm UTC](https://discourse.processing.org/t/multiple-windows-clone-one-to-another-with-pgraphics-obj/869/3 "2018-06-11T15:53:58Z")

</div>

Indeed we can transfer the contents of a PImage::_pixels[]_ to another 1 via **arrayCopy()** and long as they’ve got same _width_ & _height_. 🤑

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [June 11, 2018, 4:14pm UTC](https://discourse.processing.org/t/multiple-windows-clone-one-to-another-with-pgraphics-obj/869/4 "2018-06-11T16:14:24Z")

</div>

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](https://stackoverflow.com/q/50794029/873165)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 11, 2018, 4:18pm UTC](https://discourse.processing.org/t/multiple-windows-clone-one-to-another-with-pgraphics-obj/869/5 "2018-06-11T16:18:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bitCrasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bitcrasher/32/408_2.png) [@bitCrasher](https://discourse.processing.org/u/bitCrasher)\
**Post date:** [June 11, 2018, 4:23pm UTC](https://discourse.processing.org/t/multiple-windows-clone-one-to-another-with-pgraphics-obj/869/6 "2018-06-11T16:23:26Z")

</div>

> [@GoToLoop](#):
>
> arrayCopy

thank you!! i solved using PImage as buffer

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

```

🙂

---

<div class="post-metadata">

**Author:** ![bitCrasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bitcrasher/32/408_2.png) [@bitCrasher](https://discourse.processing.org/u/bitCrasher)\
**Post date:** [June 11, 2018, 4:25pm UTC](https://discourse.processing.org/t/multiple-windows-clone-one-to-another-with-pgraphics-obj/869/7 "2018-06-11T16:25:38Z")

</div>

i know is me!! i also wrote there!

---

<div class="post-metadata">

**Author:** ![bitCrasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bitcrasher/32/408_2.png) [@bitCrasher](https://discourse.processing.org/u/bitCrasher)\
**Post date:** [June 11, 2018, 4:28pm UTC](https://discourse.processing.org/t/multiple-windows-clone-one-to-another-with-pgraphics-obj/869/8 "2018-06-11T16:28:52Z")

</div>

ok!! next time i will link it! 🙂
