Running PGraphics on a second window

I have the following situation. I have a PGraphics that’s running without problems in the main window. I want to remove this PG from the main window and simply display it on a second window.

All the calculation and ControlP5 interaction are in the main thread so i won’t have any problems comunicating changes between threads. So i’ve checked the forums for an answer and tried a few of the solutions presented. but actually none of them worked. how do i pass the PG to the second window? i’ve tried sending the PGraphics in the constructor and nothing happened. Should i pass the PG to the second window in something like this:


this is the situation i have now:

here’s the basic code

import controlP5.*;
import com.hamoid.*;

ControlP5 cp5;
VideoExport videoExport;

//second window
PWindow win;

ParticleSystem ps;
PGraphics pg;
int w=2400;
int h=1920;
int pgOrigin=400;

//Particle Control
int speedX=0;
int speedY=0;
int spawn=0;
int pw=w;
int ph=30;
int spawnX=0;
int spawnY=h;

color fillColor=color(255);

//video export
boolean isRecording=false;

String filename="particleMaker";

void settings() {
  size(1020, 960, P2D);

void setup() {
  //setup ControlP5  

  //setup PG
  println("building PGraphics");
  pg=createGraphics(w, h, P2D);

  ps=new ParticleSystem();
  win=new PWindow();

  //setup videoexport
  videoExport = new VideoExport(this, filename+".mp4", pg);

void draw() {

  if (spawn>0 && frameCount % spawn==0) {



  image(pg, 400, 0, 600, 480);

  if (isRecording) {

void saves() {"saves/"+filename+"C/"+filename+"C-"+frameCount+".png");

void keyPressed() {
  if (key=='s') saves();

  if (key == 'r' || key == 'R') {
    isRecording = !isRecording;
    println("Recording is " + (isRecording ? "ON" : "OFF"));

  if (key == 'q') {

PWindow code

public class PWindow extends PApplet {
  PWindow() {
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
  void settings() {
    size(600, 480);

  void setup() {

  void draw() {
    image(pg, 0, 0, 600, 480);

I’ve used a workaround. not that classy or hackable, but used the good old syphon/spout solution.
since i was already outputing via syphon, it just another pipe in the system.