Fullscreen Solutions for Processing

Published on Sep. 27, 2011
by Kyle

In many scenarios, I want my final Processing application to launch in fullscreen when I have completed it. I usually don’t want any visibility of an operating system or any other process during an installation, performance or otherwise. From my experience with Processing, I have noticed the solution is often different than the last, its like a giant switch statement of how you can accomplish your goal (was it built in Eclipse or the P5 IDE, can it initialize to fullscreen or should it be commanded into that mode later, etc.). I thought it would be helpful to others if I compiled all of the different solutions and the circumstances in which each one will and will not work…

If you want fullscreen on a single window, I recommend using Processing’s built-in “present” mode. Present mode is very stable, and is the most recommended and documented method. If you use present mode, be aware that if your application crashes, you may have difficulty being able to get out of the window. You will also want the application’s size() to be set to your desired screen’s dimensions using screenWidth and screenHeight. Using the Processing IDE for sketching you can easily enter present mode by selecting “Sketch->Present” from the menu. This does not require any code. If you are using Eclipse or you would like to export your application to run in present mode you will need to override the first function called in every java application:


public static void main(String args[])
{
        //launch in "present" mode, your class is "Sketch021210" (prefix with package if used)
	PApplet.main(new String[] {"--present", "Sketch021210"});
}

If you need extra functionality, such as being able to toggle between fullscreen and windowed mode, you can use the Fullscreen API, which offers more features but can be buggy.

The Fullscreen API has caused problems for me several times, and is known to not play well with OpenGL. It has also been the best solution I have found for several projects and am very thankful for the developer that has put a lot of effort into it. The Fullscreen API previously would not render graphics on a secondary display, but a new class SoftFullScreen has made this possible. This is a great API, but should be used with caution.

If you are using multiple dedicated computers for your displays Most Pixels Ever by Daniel Shiffman and some students at ITP is a library for Processing (and also available for openFrameworks) that is simple to set up and can span across many screens. ITP students use Most Pixels Ever for their Big Screens annual show. This is a great and stable solution and will work fine whether or not you are using OpenGL. It also can have resource advantages since the computation is split between machines. Each machine communicates with the others over a server, so there is a little bit of extra set up. You also need to watch your random number generators, if your sketches use random() the computers will return different values and not remain in sync.

If you are using a single computer for multiple displays, even if you want to use OpenGL, then this is when you will need to bring your project into Eclipse and override a few pre-determined things in Processing. If you are unfamiliar with Eclipse, you may want to look at this posting I wrote: Advanced Processing in Eclipse. In my opinion, this technique is the most valuable for Processing users to know. This solution is flexible, will allow you to keep using OpenGL and it will save you the work of splitting your project onto multiple computers. This solution involves a combination of accessing Processing’s JFrame and setting it to be undecorated (which removes the system chrome), positioning the window, and then if you are on a Mac, you will use the applications info.plist file to tell OS X to hide the menu bar. Here is an explanation of the process:

  1. Before the setup() method of your sketch is called, PApplet (the core applet class for Processing) calls init(). During the init() method Processing displays the application’s JFrame, we must override this method and alter the JFrame before it is displayed (this can also be found in the processing:hacks).
  2. That will hide your system chrome by accessing the “frame” property before it is ever displayed, doing this inside setup() will not work. Your next step is to position the window. In the above link it is recommended to call frame.setLocation(x,y) immediately following size(), I have found this to not work, so I recommend doing it on your first draw().
    
    
    public void init() {
    	  /// to make a frame not displayable, you can
    	  // use frame.removeNotify()
    	  frame.removeNotify(); 
    
    	  frame.setUndecorated(true);
    
    	  // addNotify, here i am not sure if you have
    	  // to add notify again.
    	  frame.addNotify();
    	  super.init();
    }
    
    void setup()
    {
      size(2048,768); //2 1024x768 monitors horizontally
    }
    
    void draw()
    {
      if(frameCount == 1)
      {
         frame.setLocation(0,0);
       }
    }
    
    
  3. This step is only necessary if you are on a Mac: go to your jar, right-click on it and select ‘Show Package Contents’ inside the ‘Contents/’ folder is the file ‘info.plist’ open that file in XCode. On the left column you will see “Application UI Presentation Mode” that needs to be set to “All Hidden”. To change this, right-click and select “Show Raw Keys/Values” then select 3 on the right column. Save and quit.
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Twitter

Leave a response
Trackback URL: Fullscreen Solutions for Processing.