<!--
{
  "availability" : [
    "macOS: 10.0.0 - 10.14.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSOpenGLPixelFormat/init(attributes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSOpenGLPixelFormat(im)initWithAttributes:"
  },
  "title" : "init(attributes:)"
}
-->

# init(attributes:)

Returns an OpenGL pixel format object initialized with specified pixel format attributes.

```
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 <doc://com.apple.documentation/documentation/Swift/true> while its absence implies a value of <doc://com.apple.documentation/documentation/Swift/false>. Integer constants must be followed by the desired value. For a listing of attribute constants, see the constants in [OpenGL Pixel Format Attributes](/documentation/AppKit/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 <doc://com.apple.documentation/documentation/Swift/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:

```objc
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. */
}
```

## See Also

[`-  getValues:forAttribute:forVirtualScreen:`](/documentation/AppKit/NSOpenGLPixelFormat/getValues(_:forAttribute:forVirtualScreen:))

Gets the value for the specified pixel format attribute.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)