How to start sketch fullscreen or windowed with v3.0 depending on start command ?

There are 2 possibilities to start a sketch:

  • Sketch Run (Ctrl-R) run windowed

  • Sketch Present (Ctrl-Shift-R) run fullscreen

In case of sketch is started with 'Run' command, a window with defined size should be opened. e.g.: size(800, 480, P3D);

On the other hand, it should be startet fullscreen! e.g.: size(displayWidth, displayHeight, P3D);

This will result e.g. to this coding:

// fullScreen should become a global variable provided by Processing! 
boolean fullScreen = false; // true if started with Ctrl-Shift-R
                            // false if startet with Ctrl-R 
void setup()
{ if (fullScreen)
     size(displayWidth, displayHeight);  // start full screen
  if (!fullScreen)
    size(800, 480);                  // start windowed
}
void draw()
{ background(111);
  textSize(60);
  textAlign(CENTER, CENTER);
  text ("drawing size: " + width + "*" + height, width/2, height/2-60);
  text ("screen size: " + displayWidth + "*" + displayHeight, width/2, height/2+60);
}     // this example works with processing v2.2.1.

But with processing v3.0 it's not allowed to use size(x,y,mode) twice. See https://processing.org/reference/size_.html

Now some questions about this starting problem:

  • Can I get an information on how the sketch was started?

  • Is it possible to start a sketch with defined window size or fullscreen depending on the start command?

  • If mode=JavaScript, sketch should start with a defined window size. If mode=Android, sketch should always be started fullscreen. How can this be made?

ps. Some infos about it

https://github.com/processing/processing/wiki/Window-Size-and-Full-Screen

Answers

  • edited October 2015 Answer ✓
    • I've found out a present mode solution for JAVA2D renderer! \m/
    • However even after many hours, can't tame P2D & P3D.
    • And new newcomer FX2D doesn't have present mode yet I'm afraid.
    • Even though only working correctly for JAVA2D, gonna post it here so some1 else might fix it.
    • Just call checkAndSetPresentMode() inside setup() once you've got size() set: :ar!

    boolean checkAndSetPresentMode() {
      final PSurface surf = getSurface();
      final PGraphics graph = getGraphics();
      final boolean isPresentMode;
    
      if (graph.isGL()) {
        isPresentMode = ((PSurfaceJOGL) surf).pgl.presentMode();
        if (isPresentMode)  setSizePGLHack();
        return isPresentMode;
      }
    
      isPresentMode = displayWidth ==
        (graph instanceof processing.javafx.PGraphicsFX2D
        ? (int) ((javafx.scene.canvas.Canvas) surf.getNative()).getWidth()
        : ((processing.awt.PSurfaceAWT.SmoothCanvas) surf.getNative()).getFrame().getWidth());
    
      if (isPresentMode)  surf.setSize(displayWidth, displayHeight);
      return isPresentMode;
    }
    
    void setSizePGLHack() {
      final PSurface surf = getSurface();
      final PGraphics graph = getGraphics();
      final PGL gl = ((PSurfaceJOGL) surf).pgl;
      final java.lang.reflect.Field scr, present;
    
      gl.presentX = gl.presentY = 0;
      graph.setSize(displayWidth, displayHeight);
    
      try {
        (scr = PSurfaceJOGL.class.getDeclaredField("screenRect")).setAccessible(true);
        ((java.awt.Rectangle) scr.get(surf)).setBounds(0, 0, displayWidth, displayHeight);
    
        (present = PGL.class.getDeclaredField("presentMode")).setAccessible(true);
        present.setBoolean(gl, false);
        surf.setSize(displayWidth, displayHeight);
        present.setBoolean(gl, true);
      }
    
      catch (ReflectiveOperationException ex) {
        throw new RuntimeException(ex);
      }
    
      surf.setLocation(0, 0);
      surf.placeWindow(null, null);
    
      gl.presentX = gl.presentY = 0;
      graph.setSize(displayWidth, displayHeight);
    }
    
  • edited October 2015

    Thanx for your hint! You have to dig deep in the bowels of processing for that solution. Because processing v3.0 forbit double 'size()' and 'fullScreen()' usage, I think this topic can only be solved by the developer team of processing !

    Dear developers, please can you think about an easy to use solution for all users?

    I was checking your function and its working! Starting full screen mode switches to full screen, but e.g. calling surface.setSize(500,500); freezes the sketch (tested under Win-7 Pro SP1, processing v3.0 64 bit).

    I use this test frame:

        //-----------------------------------------------------
        boolean isFullScreen = false; // true if started with Ctrl-Shift-R
                                      // false if startet with Ctrl-R 
        void setup()
        {
          size(800, 480, P3D);
          // switch to full screen mode, if sketch was started in 'Present Mode' (Ctrl-Shift-R)
          isFullScreen = checkAndSetPresentMode();
          println ("display : " +width +"*" +height);
          if (!isFullScreen)
            surface.setResizable(true);  // v3.0 only!
        }  
        void draw()
        {
          background(0);
          text ("screen: " +displayWidth +"*" +displayHeight, 22, 40);
          if ((displayWidth == width) && (displayHeight == height))
            text ("started in fullscreen mode", 22, 70);
          else  
            text ("started in window mode", 22, 70);
          text ("resolution: " +width +"*" +height, 22, 100);
        }
        void keyPressed()
        {
          if (key == 'f') setSizePGLHack();  // switch to full screen
          if (key == 'w') surface.setSize(500,500);  // v3.0 only!
        }
    
  • edited October 2015
    • I've warned you that only for JAVA2D renderer the hack is working right! :ar!
    • Also I was not thinking about switching presentMode on & off.
    • As requested, check whether sketch was run w/ CTRL+SHIFT+R presentMode or not.
    • If so, then setSize() it to displayWidth & displayHeight dimensions.
  • edited October 2015

    Starting full screen mode switch to full screen, but than it freezes, only a black screen...

    It doesn't freeze for me! Rather erratic positioning behavior.
    Below my test case I was using to "develop" my hack: :P

    /**
     * Clockwise Pathway Circle (v1.11)
     * GoToLoop (2015-Oct-14)
     *
     * forum.Processing.org/two/discussion/12995/
     * ellipse-moving-in-a-square-pathway-continuously
     *
     * studio.ProcessingTogether.com/sp/pad/export/ro.9DEx177ceWoBc
     */
    
    static final short DIAM = 0100, RAD = DIAM>>1;
    static final float SPD = 10, BOLD = 2.5;
    static final boolean ONLINE = 1/2 == 1/2.;
    
    static final PVector N = new PVector(0, -SPD, #FFFF00);
    static final PVector S = new PVector(0, SPD, #FF00FF);
    static final PVector W = new PVector(-SPD, 0, #00FFFF);
    static final PVector E = new PVector(SPD, 0, #008000);
    
    final PVector loc = new PVector(RAD, RAD);
    PVector vel = S;
    boolean isClockwise = false;
    
    void setup() {
      size(800, 480, P2D);
      smooth(4);
      frameRate(60);
    
      println(checkAndSetPresentMode());
      println(width, height);
    
      ellipseMode(CENTER);
      strokeWeight(BOLD);
      stroke(0);
    }
    
    void draw() {
      constrainToBorder();
      loc.add(vel);
    
      background(-1);
      fill((color) vel.z);
      ellipse(loc.x, loc.y, DIAM, DIAM);
    
      if (!ONLINE)  surface.setTitle(loc + " - " + vel + " - " + frameCount);
    }
    
    void keyPressed() {
      isClockwise ^= true;
    
      if      (vel == E)  vel = isClockwise? S : N;
      else if (vel == S)  vel = isClockwise? W : E;
      else if (vel == W)  vel = isClockwise? N : S;
      else                vel = isClockwise? E : W;
    }
    
    void mousePressed() {
      keyPressed();
    }
    
    void constrainToBorder() {
      if      (vel == E && loc.x > width  - RAD - SPD)  vel = isClockwise? S : N;
      else if (vel == S && loc.y > height - RAD - SPD)  vel = isClockwise? W : E;
      else if (vel == W && loc.x < RAD + SPD)           vel = isClockwise? N : S;
      else if (vel == N && loc.y < RAD + SPD)           vel = isClockwise? E : W;
    }
    
    boolean checkAndSetPresentMode() {
      final PSurface surf = getSurface();
      final PGraphics graph = getGraphics();
      final boolean isPresentMode;
    
      if (graph.isGL()) {
        isPresentMode = ((PSurfaceJOGL) surf).pgl.presentMode();
        if (isPresentMode)  setSizePGLHack();
        return isPresentMode;
      }
    
      isPresentMode = displayWidth ==
        (graph instanceof processing.javafx.PGraphicsFX2D
        ? (int) ((javafx.scene.canvas.Canvas) surf.getNative()).getWidth()
        : ((processing.awt.PSurfaceAWT.SmoothCanvas) surf.getNative()).getFrame().getWidth());
    
      if (isPresentMode)  surf.setSize(displayWidth, displayHeight);
      return isPresentMode;
    }
    
    void setSizePGLHack() {
      final PSurface surf = getSurface();
      final PGraphics graph = getGraphics();
      final PGL gl = ((PSurfaceJOGL) surf).pgl;
      final java.lang.reflect.Field scr, present;
    
      gl.presentX = gl.presentY = 0;
      graph.setSize(displayWidth, displayHeight);
    
      try {
        (scr = PSurfaceJOGL.class.getDeclaredField("screenRect")).setAccessible(true);
        ((java.awt.Rectangle) scr.get(surf)).setBounds(0, 0, displayWidth, displayHeight);
    
        (present = PGL.class.getDeclaredField("presentMode")).setAccessible(true);
        present.setBoolean(gl, false);
        surf.setSize(displayWidth, displayHeight);
        present.setBoolean(gl, true);
      }
    
      catch (ReflectiveOperationException ex) {
        throw new RuntimeException(ex);
      }
    
      surf.setLocation(0, 0);
      surf.placeWindow(null, null);
    
      gl.presentX = gl.presentY = 0;
      graph.setSize(displayWidth, displayHeight);
    }
    
  • With this hack the sketch can be started full screen with the Ctrl-Shift-R command, but the moving circle is only visible, if it is located within the rectangle given bei the 'size(800, 480, P2D);' command on my PC (Win7).

  • At the end the answers of my questions are...

    Can I get an information on how the sketch was started?
    

    --> NO

    Is it possible to start a sketch with defined window size or fullscreen depending on the start command?
    

    --> YES, but drawing fails afterwards

    If mode=JavaScript, sketch should start with a defined window size. 
    If mode=Android, sketch should always be started fullscreen. How can this be made?
    

    --> at the moment there is no JavaScript available :-(

    So I only can repeat my request of this requirements. Dear developers, please can you think about an easy to use solution for all users?

  • At the moment there is no JavaScript available.

    https://GitHub.com/fjenett/javascript-mode-processing/issues/33

    Dear developers, please can you think about an easy to use solution for all users?

    https://GitHub.com/processing/processing/issues

Sign In or Register to comment.