Initializing Stereo

This section breaks initialization into two steps:

Setting up Stereo

Initializing stereo is fairly easy. You will:

  1. Initialize the SDK.
  2. Set up left/right frame detection by creating a "stereo buffer." The stereo buffer is simply a wrapper for left/right frame detection.
  3. Create one or more stereo viewports. The viewport is abstract, not an actual window or viewport that is created and registered through the OS. Each viewport manages a stereo frustum.
  4. Get the handle to each viewport's stereo frustum. The stereo frustum is responsible for all stereoscopic 3D calculations.

The following code example illustrates these steps. Error handling is omitted for brevity.

  ZSContext g_zSpaceContext  = NULL;
  ZSHandle  g_bufferHandle   = NULL;
  ZSHandle  g_viewportHandle = NULL;
  ZSHandle  g_frustumHandle  = NULL;

  // Initialize the zSpace SDK. This MUST be called before 
  // calling any other zSpace API. 
  zsInitialize(&g_zSpaceContext);
  
  // Create a stereo buffer to handle L/R detection. 
  zsCreateStereoBuffer(g_zSpaceContext, ZS_RENDERER_QUAD_BUFFER_GL, 0, &g_bufferHandle);
  
  // Create a zSpace viewport object and grab its associated frustum.  
  // The viewport manages a zSpace stereo frustum. 
  zsCreateViewport(g_zSpaceContext, &g_viewportHandle);
  zsFindFrustum(g_viewportHandle, &g_frustumHandle); 

For a more complete example, refer to the Basic Stereo sample application in the Samples\Render subdirectory. The code examples in this manual closely follow the OpenGL sample, but the SDK also includes examples for D3D9, D3D10, D3D11, and D3D11_1.

Read the following paragraphs for further explanation of the above functions.

Call zsInitialize() once per zSpace session. zsInitialize() loads the zSpace SDK's runtime DLL, detects connected peripherals, and creates the handles for the display and tracked targets. The sections on Display Basics and Tracking Basics show you how to get those handles.

Call zsCreateStereoBuffer() once to set up left/right frame detection. Left/right frame detection is discussed more in Updating the Scene.

Call zsCreateViewport() to create both the stereo viewport and its stereo frustum:

Creating the Render Context

As part of initialization, you must also create a stereo-enabled application window and render context. The following example demonstrates how to set up the pixel format descriptor for a stereo-enabled OpenGL render context:

  // Set the appropriate pixel format.
  PIXELFORMATDESCRIPTOR pfd =                                   
  {
    sizeof(PIXELFORMATDESCRIPTOR),      // Size Of This Pixel Format Descriptor
    1,                                  // Version Number
    PFD_DRAW_TO_WINDOW |                // Format Must Support Window
    PFD_SUPPORT_OPENGL |                // Format Must Support OpenGL
    PFD_STEREO         |                // Format Must Support Quad-buffer Stereo
    PFD_DOUBLEBUFFER,                   // Must Support Double Buffering
    PFD_TYPE_RGBA,                      // Request An RGBA Format
    24,                                 // 24-bit color depth
    0, 0, 0, 0, 0, 0,                   // Color Bits Ignored
    0,                                  // No Alpha Buffer
    0,                                  // Shift Bit Ignored
    0,                                  // No Accumulation Buffer
    0, 0, 0, 0,                         // Accumulation Bits Ignored
    32,                                 // 32-bit Z-Buffer (Depth Buffer)
    0,                                  // No Stencil Buffer
    0,                                  // No Auxiliary Buffer
    PFD_MAIN_PLANE,                     // Main Drawing Layer
    0,                                  // Reserved
    0, 0, 0                             // Layer Masks Ignored
  };