---
title: "init(cglContextObj:)"
framework: appkit
role: symbol
role_heading: Initializer
path: "appkit/nsopenglcontext/init(cglcontextobj:)-30lqr"
---

# init(cglContextObj:)

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

## Declaration

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

## Parameters

- `context`: The CGL context to wrap inside the doc://com.apple.appkit/documentation/AppKit/NSOpenGLContext object.

## Return Value

Return Value An initialized context.

## Discussion

Discussion If your application already has a CGL context, you can wrap a NSOpenGLContext object around it using this method. This method retains the CGL context by calling CGLRetainContext(_:). Only one 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.

## See Also

### Creating Contexts

- [init(format:share:)](appkit/nsopenglcontext/init(format:share:).md)
