render on window graphics in another

edited October 2015 in How To...

Hi. I'm working in a two windows project. First one renders the sketch, second one is intended to control the sketch (with buttons, etc). Btw, I'm working with Eclipse.

As main window will be projected in a wall, and I want to take ride of the mouse cursor, I wonder if there's a way to reproduce the first window content in a little area of the second window, and control mouse events from there. Event's handling would be quite simple, but I'm not sure on how to render content from one window to another.

Answers

  • Great. Thanks. I'm on the way now.

  • Actually, readings are being interesting, but I still don't know how to draw the exact same content from one window into a section of the another window.

    I suspect there's a method to get the graphics from one applet and draw that in another place. I'm looking for it.

  • Thanks. I'm trying things like that.

    ie:

    public void drawVideoPad(){
            
            PImage pimage = mainWindow.getGraphics().get();
            pimage.resize(512, 384);
            
            // video pad
            fill(100);
            rect(250, 50, 512, 384);
            image(pimage, 250, 50);
        }
    

    and

    public void drawVideoPad(){
            
            mainWindowGraphics = mainWindow.getGraphics();
            mainWindowGraphics.resize(512, 384);
            
            // video pad
            fill(100);
            rect(250, 50, 512, 384);
            image(mainWindowGraphics, 250, 50);
        }
    

    First example leaves main windows black (erasing original content).

  • edited October 2015

    Processing 1 & 2:

    // forum.Processing.org/two/discussion/13233/render-on-window-graphics-in-another
    // GoToLoop (2015-Oct-27)
    
    static volatile PImage mirror = new PImage(500, 400);
    
    void setup() {
      size(800, 600);
      frameRate(3);
      runSketch(platformNames, new Mirrored());
    }
    
    void draw() {
      background((color) random(#000000));
      synchronized (JAVA2D) {
        (mirror = get()).resize(500, 400);
      }
    }
    
    static class Mirrored extends PApplet {
      void setup() {
        size(500, 400);
        frameRate(30);
      }
    
      void draw() {
        synchronized (JAVA2D) {
          background(mirror);
        }
      }
    }
    
  • edited October 2015

    Processing 3:

    // forum.Processing.org/two/discussion/13233/render-on-window-graphics-in-another
    // GoToLoop (2015-Oct-27)
    
    static PImage mirror = new PImage(500, 400);
    
    void settings() {
      size(800, 600);
    }
    
    void setup() {
      frameRate(3);
      runSketch(platformNames, new Mirrored());
    }
    
    void draw() {
      background((color) random(#000000));
      synchronized (DXF) {
        (mirror = get()).resize(500, 400);
      }
    }
    
    static class Mirrored extends PApplet {
      void settings() {
        size(500, 400);
      }
    
      void setup() {
        frameRate(30);
      }
    
      void draw() {
        synchronized (DXF) {
          background(mirror);
        }
      }
    }
    
  • Cool, that worked. Thanks a lot.

    I just adapted the code for Eclipse.

Sign In or Register to comment.