<!--
{
  "availability" : [
    "macOS: 10.6.0 - 10.14.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSOpenGLContext/init(cglContextObj:)-30lqr",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSOpenGLContext(im)initWithCGLContextObj:"
  },
  "title" : "init(cglContextObj:)"
}
-->

# init(cglContextObj:)

Initializes and returns an OpenGL context object using an existing CGL context.

```
init?(cglContextObj context: CGLContextObj)
```

## Parameters

`context`

The CGL context to wrap inside the [`NSOpenGLContext`](/documentation/AppKit/NSOpenGLContext) object.

## Return Value

An initialized context.

## Discussion

If your application already has a CGL context, you can wrap a [`NSOpenGLContext`](/documentation/AppKit/NSOpenGLContext) object around it using this method. This method retains the CGL context by calling `CGLRetainContext(_:)`.

Only one [`NSOpenGLContext`](/documentation/AppKit/NSOpenGLContext) object can wrap a specific context.

Your application should not call `CGLDestroyContext(_:)` to dispose of the CGL context. Instead, your application should call `CGLReleaseContext(_:)` to decrement its reference count.

---

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)