<!--
{
  "availability" : [
    "macOS: 10.6.0 - 10.14.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSOpenGLLayer/openGLContext(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSOpenGLLayer(im)openGLContextForPixelFormat:"
  },
  "title" : "openGLContext(for:)"
}
-->

# openGLContext(for:)

Returns the OpenGL context to use for the requested pixel format.

```
func openGLContext(for pixelFormat: NSOpenGLPixelFormat) -> NSOpenGLContext
```

## Parameters

`pixelFormat`

The pixel format.

## Return Value

An autoreleased [`NSOpenGLContext`](/documentation/AppKit/NSOpenGLContext).

---

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)