fullScreen() in processing 3.0a5

I noticed fullScreen() doesn't work (function doesn't exitst) in processing 3.0a5. Is there another way of switching screens mid-sketch?

Answers

    • Processing 3.0a5 was the last version which had PApplet extending Java's Applet.
    • For all effects, all alpha versions up to 3.0a5 can be considered Processing 2.2.1.
    • And thus you should look for those older approaches for fullscreen, which was called Present Mode back then.
  • Thanks for replying. So lets say I want to switch screens halfway in a sketch, would this work?

    final PApplet projector = new ProjectorSketch();
    
    void setup() {
      size(300, 300, JAVA2D);
      smooth(4);
      noLoop();
      stroke(-1);
    
      runSketch(new String[] { "--display=1", "--present", "Projector" }, projector);
    }
    
    void draw() {
      background(0);
      line(0, 0, width, height);
    }
    
    void keyPressed()
    {
      if(key == 'a')
      {
        final PApplet projector = new ProjectorSketch();
        runSketch(new String[] { "--display=0", "--present", "Projector" }, projector);
      }
    }
    
    class ProjectorSketch extends PApplet {
      void setup() {
        size(displayWidth, displayHeight, JAVA2D);
        smooth(4);
        noLoop();
        stroke(#FFFF00);
      }
    
      void draw() {
        background(0);
        line(width, 0, 0, height);
    
        println(projector);
      }
    }
    
  • edited February 2016

    I think I worded my question wrong. I want to have a single sketch and move it from one display to another when I press a key, the example seems to be bouncing between two sketches already initialized on two different screens.

  • // forum.Processing.org/two/discussion/14660/fullscreen-in-processing-3-0a5
    // GoToLoop (2016-Feb-03)
    
    void setup() {
      size(displayWidth, displayHeight);
      frameRate(1);
    }
    
    void draw() {
      background((color) random(#000000));
    }
    
    @ Override boolean sketchFullScreen() {
      return true;
    }
    
  • This makes the sketch full screen? How do I move it from my main screen to a monitor I've attached?

  • edited February 2016
    • I don't believe Processing 2 (and 3.0a5) got some function to choose which monitor to use like Processing 3 w/ its fullScreen().
    • In order to access such hidden configurations we're gonna need to implement our own main() over Processing's default.
    • And we also need to build our own String[] w/ "--display=1" + "--present".
    • Then invoke PApplet.main() from there, passing our String[] to it.
    • Unfortunately we end up losing sketchPath when running from the PDE.
    • Although we can have it back if we export the sketch and run it from the command line.

    // forum.Processing.org/two/discussion/14660/fullscreen-in-processing-3-0a5
    // GoToLoop (2016-Feb-04)
    
    static final void main(final String[] args) {
      final String sketch = Thread.currentThread().getStackTrace()[1].getClassName();
      final String[] monitor = { "--display=1", "--present" };
      final String[] params = concat(append(monitor, sketch), args);
    
      PApplet.main(params);
    }
    
    void setup() {
      size(displayWidth, displayHeight);
      frameRate(1);
    }
    
    void draw() {
      background((color) random(#000000));
    }
    
  • edited February 2016

    Cool, but it looks like the string array 'monitor' is final. How can you change it in the middle of a sketch? Will this work?

    void keyPressed()
    {
    if(key == 'a')
    {
    monitor[0] = "--display=0";
    }
    } 
    
  • edited February 2016 Answer ✓
    • That static final void main(final String[] args) {} method is to instantiate the whole sketch.
    • I dunno about any hack which would allow to switch the desired display once sketch had started.
    • That is internal implementation knowledge farther beyond I can reach right now, sorry
    • If you need to target 2 diff. projector displays, you're gonna need 2 running PApplet instances.
    • You've already know how to instantiate extra PApplet via runSketch().
    • And you know how to hide()/show() via setVisible().
    • And pause/resume sketch via noLoop()/loop().
    • Only thing you need is some clever way to tame 2 PApplet instances running the same algorithm, but targeting 2 diff. monitor w/ diff. resolutions.
    • There are many ways to solve it. 1 approach is having a shared PGraphics.
    • 1 PApplet modified the PGraphics w/ its own size() monitor resolution.
    • The other uses image() to display it at the external projector.
    • Passing 4 arguments allows it to be rescaled to some specific dimension:
      image(pg, 0, 0, width, height);
    • In other words, both sketches gonna display the same PGraphics w/ their respective resolution.
  • Thanks so much! I think I understand what I need to do now.

  • edited February 2016

    Another question. Is it possible to make an array of PApplets? I'm thinking of getting the number of displays using the following way:

    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = env.getScreenDevices();
    int numberofScreens = devices.length;  
    

    And using this integer to create 1 PApplet for each screen. Then I can just switch back and forth using enable / disable.

    • My knowledge about graphics internals is very poor.
    • But aFaIK, you only need 1 extra PApplet instance.
    • The 1st 1 we already got it free after all.
    • Just use runSketch() passing to it your extra PApplet class.
    • You can hide/show it setVisible() + noLoop() & loop() whenever you want to.
    • Its only objective is displaying the shared PGraphics via image() w/ 5 arguments:
      image(pg, 0, 0, width, height); https://Processing.org/reference/image_.html
    • This way, you can have both displays showing the same image w/ diff. scales.
  • edited May 2017

    This works great in development mode. But when I export the application and run the sketch the projector sketch doesnt run properly. Sometimes it runs, sometimes I get a weird gray screen with a small box in the center or the corner. Here is the code:

    //Output sketch
    Projector projector;
    
    //Output window dimensions
    int scrW, scrH;
    
    //This is used to determine the dimensions of the output display
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = env.getScreenDevices();
    int numberofScreens = devices.length; 
    
    PImage bg;
    
    void setup()
    {
      bg = loadImage("img.jpg");
    
      sH = bg.width;
      sV = bg.height;
    
      size(sH,sV);
    
    
     scrW = devices[0].getDefaultConfiguration().getBounds().width;
     scrH = devices[0].getDefaultConfiguration().getBounds().height;
    
      //Load with controls on the page
      setMode = true;  
    
      final String[] projectorArgs = {
        "--display=1", 
        "--present", 
        "--sketch-path=" + sketchPath, 
        ""
      };
    
      try
      {
        projector = new Projector(scrW, scrH); // instantiate
        runSketch(projectorArgs, projector); // ignite
      }
      catch(Exception e)
      {
      }
    }
    

    Am I doing something wrong?

Sign In or Register to comment.