Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Using CGL to Create a Full-Screen Context

Because the CGL API is at a lower level in the system architecture than either Cocoa or the AGL API, you can use it to create a full-screen context in either a Cocoa or a Carbon application. The code in Listing 3-3 shows how to capture the main display and create a full-screen context. As you can see, the code parallels the examples shown in “Using Cocoa to Create a Full-Screen Context” and “Using AGL to Create a Full-Screen Context.” A detailed explanation for each numbered line of code appears following the listing.

Depending on what you want to accomplish, there are a number of modifications that you can make to the code, such as adjusting the display mode and synchronizing rendering to the screen refresh rate. See “Adjusting Display Modes” and “Quartz Display Services and Full-Screen Mode.”

Listing 3-3  Setting up a full-screen context using CGL

CGDisplayCapture (kCGDirectMainDisplay); // 1
CGLPixelFormatAttribute attribs[] = { kCGLPFADoubleBuffer,
        kCGLPFAFullScreen,
        kCGLPFADisplayMask,
        CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay),
        NULL
    }; // 2
CGLPixelFormatObj pixelFormatObj;
long numPixelFormats ;
 
CGLChoosePixelFormat( attribs, &pixelFormatObj, &numPixelFormats );
 
CGLContextObj contextObj ;
CGLCreateContext( pixelFormatObj, NULL, &contextObj );
 
CGLDestroyPixelFormat( pixelFormatObj );
 
CGLSetCurrentContext( contextObj ); // 3
CGLSetFullScreen( contextObj );// 4
 
//****** Perform your application's main loop
 
CGLSetCurrentContext(NULL); // 5
CGLClearDrawable(contextObj);
CGLDestroyContext(contextObj);
CGReleaseAllDisplays();

Here's what the code does:

  1. Captures the main display.

  2. Sets up an array of attributes that includes the full-screen attribute and the display mask associated with the captured display.

  3. Sets the current context to the one it will use for full-screen drawing.

  4. Attaches a full-screen drawable object to the current context.

  5. After all drawing is completed, sets the current context to NULL, and goes on to perform the other necessary clean up work: clearing the drawable object, destroying the rendering context, and releasing the displays.



< Previous PageNext Page > Hide TOC


Last updated: 2008-06-09




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice