My favorites | English | Sign in

Switching to Full-Screen Mode

Introduction

In full-screen mode, all browser buttons and toolbars are removed, and only the O3D window is visible. In O3D applications, this mode is activated by an explicit user gesture—clicking on a special region displayed on the screen for this purpose. In full-screen mode, the screen resolution is set by the O3D application.

User Interaction

When the user clicks on a specified rectangular region, O3D switches to full-screen mode, and the following message appears on the screen for a few seconds:

Press ESC to exit fullscreen.

Pressing Escape or pressing any other key sequence that causes the foreground window to lose focus (for example, pressing Alt+Tab in Windows or Command+Tab in OSX) also takes O3D back to plug-in mode.

Related API Calls

The following API calls play an important role in switching to full-screen mode:

client.getDisplayModes()
This function returns an array that enumerates the available screen modes on this system. The array contains the resolution and the refresh rate for each possible mode. (The refresh rate reported may be 0 if the O3D plug-in is running on an LCD monitor.) The display mode is passed in to the setFullScreenClickRegion() method. Specifying a mode of Renderer.DISPLAY_MODE_DEFAULT indicates to use the refresh rate and resolution of the current screen mode.
client.setFullscreenClickRegion(Number x, Number y, Number width, Number height, Number mode_id)
This function sets a region of the plug-in that, if clicked by the user, activates full-screen mode. This region is not visible. You are responsible for setting up the user interface that corresponds to this region, as well as resizing the region if the plug-in window is resized. The x, y coordinates of this region are relative to the top-left corner of the plug-in region. The x and y coordinates, as well as the width and height, are measured in pixels.
o3djs.event.addEventListener(Element pluginObject, string event_type, Object callback_function)
This is a handy utility function that manages an event listener on the O3D plug-in object. By listening for the resize event, an application can be alerted when O3D switches to full-screen mode.
client.cancelFullScreenDisplay()
If the application is in full-screen mode, this function returns the display to plug-in mode, restricting content to the plug-in region; if the application is already in plug-in mode, this function call has no effect. Note that this call does not clear the clickable region. The region remains active until clearFullscreenClickRegion() is called, or until it is replaced by setFullscreenClickRegion().
client.clearFullscreenClickRegion()
This function deactivates the rectangle specified as the clickable region.

Code Sample

The fullscreen.html sample modifies the helloworld.html sample to toggle between plug-in and full-screen modes. This section highlights key tasks performed in this sample.

Querying the Display Mode

In this example, the getFullscreenModeId() function queries the system and selects the mode to use. This return value is then passed in to setFullscreenClickRegion().

function getFullscreenModeId() {
  var displayModes = g_client.getDisplayModes();
  var bestMode;
  for (var index in displayModes) {
    var mode = displayModes[index];
    if (!bestMode ||
        (mode.width > bestMode.width && mode.height > bestMode.height)) {
      bestMode = mode;
    }
  }
  if (bestMode) {
    return bestMode.id;
  } else {
    return g_o3d.Renderer.DISPLAY_MODE_DEFAULT;  // getDisplayModes isn't implemented on all platforms yet
  }
}

Displaying the User Click Region

The setFullscreenClickRegion() function sets up the area on the screen that activates full-screen mode, but you are responsible for creating the accompanying graphical user interface (GUI) that corresponds to this rectangle. In the fullscreen.html example, the createBannerSurfaceAndClickableRegion() function performs these related tasks:

  • Creates a material.
  • Loads a texture into the material. (This texture contains the text for the clickable region.)
  • Creates a polygon for the texture.
  • Sets up an event handler to listen for the resize event.
  • Set up the clickable region on the screen.

Here is the code for adding the event listener and setting up the clickable region, which occurs at the end of the createBannerSurfaceAndClickableRegion() function):.

o3djs.event.addEventListener(g_o3dElement, 'resize', handleResizeEvent);
g_client.setFullscreenClickRegion(10, clientHeight - texture.height - 10,
          texture.width, texture.height, getFullscreenModeId());

The call for a resize event receives an event object that contains the dimensions of the window you're drawing into and a flag that indicates whether you're in full-screen mode.

Setting Up Two Views

The fullscreen.html sample sets up two views, a perspective view (g_viewInfo) for the 3D teapot scene, and an orthographic view (orthoViewInfo) that is drawn after (that is, on top of) the 3D scene. The orthographic view contains the textured rectangle that corresponds to the clickable region for full-screen mode.

The setUpBanner() function creates the orthographic view for the 2D user interface "layer." This view turns off the clear color flag so that the 3D view remains on the screen. It sets the priority for the orthographic view to one greater than that of the perspective view, so that it is drawn after the perspective view (g_viewInfo):

function setupBanner(width, height, viewInfo) {
  g_orthoRoot = g_pack.createObject('Transform');

  // Create a view for the orthographic display of the fullscreen banner.
  var orthoViewInfo = o3djs.rendergraph.createBasicView(
        g_pack,
        g_orthoRoot,
        g_client.renderGraphRoot);

  // Make sure the orthographic view gets drawn after the 3d stuff
  orthoViewInfo.root.priority = g_viewInfo.root.priority + 1;

  // Turn off clearing the color for the orthographic view, since that would
  // erase the 3d parts.  Leave clearing the depth and stencil, so it's
  // unaffected by anything done by the 3d parts.
  orthoViewInfo.clearBuffer.clearColorFlag = false;
  .
  .
  .
}

See the Creating a heads-up display sample for another example of creating a 2D overlay and an accompanying 3D view.