Returns an NSOpenGLPixelFormat object initialized with specified pixel format attributes.


convenience init?(attributes attribs: UnsafePointer<NSOpenGLPixelFormatAttribute>)



A 0-terminated array containing Boolean and integer attribute constants. The presence of a Boolean attribute implies a value of true while its absence implies a value of false. Integer constants must be followed by the desired value. For a listing of attribute constants, see the table in Constants.

Return Value

An initialized NSOpenGLPixelFormat object whose attributes match the desired attributes as close as possible, or nil if an object with the desired attributes could not be initialized.


On return, the Boolean attributes of the receiver match the values specified in attribs, and the integer attributes are as close to the specified values as can be provided by the system.

The existence of a Boolean attribute constant in attribs implies a true value. The Boolean attribute constants are:

  • NSOpenGLPFAAllRenderers

  • NSOpenGLPFADoubleBuffer

  • NSOpenGLPFAStereo

  • NSOpenGLPFAMinimumPolicy

  • NSOpenGLPFAMaximumPolicy

  • NSOpenGLPFAOffScreen

  • NSOpenGLPFAFullScreen

  • NSOpenGLPFASingleRenderer

  • NSOpenGLPFANoRecovery

  • NSOpenGLPFAAccelerated

  • NSOpenGLPFAClosestPolicy

  • NSOpenGLPFARobust

  • NSOpenGLPFABackingStore

  • NSOpenGLPFAWindow

  • NSOpenGLPFAMultiScreen

  • NSOpenGLPFACompliant

  • NSOpenGLPFAPixelBuffer

The integer constants must be followed by a value. These constants are:

  • NSOpenGLPFAAuxBuffers

  • NSOpenGLPFAColorSize

  • NSOpenGLPFAAlphaSize

  • NSOpenGLPFADepthSize

  • NSOpenGLPFAStencilSize

  • NSOpenGLPFAAccumSize

  • NSOpenGLPFARendererID

  • NSOpenGLPFAScreenMask

This code fragment creates a double-buffered pixel format with a 32-bit depth buffer:

NSOpenGLPixelFormatAttribute attrs[] =
    NSOpenGLPFADepthSize, 32,
NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
/* Check if initWithAttributes succeeded. */
if(pixFmt == nil) {
    /* initWithAttributes failed. Try to alloc/init with a different  list of attributes. */

See Also

Creating an NSOpenGLPixelFormat Object

init?(cglPixelFormatObj: CGLPixelFormatObj)

Returns an NSOpenGLPixelFormatobject initialized with using an existing CGL pixel format object.