init(attributes:)
Returns an OpenGL pixel format object initialized with specified pixel format attributes.
Declaration
convenience init?(attributes attribs: UnsafePointer<NSOpenGLPixelFormatAttribute>)Parameters
- attribs:
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 constants in Opengl Pixel Format Attributes.
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.
Discussion
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:
NSOpenGLPFAAllRenderersNSOpenGLPFADoubleBufferNSOpenGLPFAStereoNSOpenGLPFAMinimumPolicyNSOpenGLPFAMaximumPolicyNSOpenGLPFAOffScreenNSOpenGLPFAFullScreenNSOpenGLPFASingleRendererNSOpenGLPFANoRecoveryNSOpenGLPFAAcceleratedNSOpenGLPFAClosestPolicyNSOpenGLPFARobustNSOpenGLPFABackingStoreNSOpenGLPFAWindowNSOpenGLPFAMultiScreenNSOpenGLPFACompliantNSOpenGLPFAPixelBuffer
The integer constants must be followed by a value. These constants are:
NSOpenGLPFAAuxBuffersNSOpenGLPFAColorSizeNSOpenGLPFAAlphaSizeNSOpenGLPFADepthSizeNSOpenGLPFAStencilSizeNSOpenGLPFAAccumSizeNSOpenGLPFARendererIDNSOpenGLPFAScreenMask
This code fragment creates a double-buffered pixel format with a 32-bit depth buffer:
NSOpenGLPixelFormatAttribute attrs[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFADepthSize, 32,
0
};
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. */
}