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

# NSOpenGLContext

An object that represents an OpenGL graphics context, into which all OpenGL calls are rendered.

```
class NSOpenGLContext
```

## Overview

An OpenGL context is created using an [`NSOpenGLPixelFormat`](/documentation/AppKit/NSOpenGLPixelFormat)object that specifies the context’s buffer types and other attributes. A context can be full-screen, offscreen, or associated with an [`NSView`](/documentation/AppKit/NSView) object. A context draws into its *drawable object*, which is the frame buffer that is the target of OpenGL drawing operations.

Every [`NSOpenGLContext`](/documentation/AppKit/NSOpenGLContext) object wraps a low-level, platform-specific Core OpenGL (CGL) context. Your application can retrieve the CGL context by calling the [`cglContextObj`](/documentation/AppKit/NSOpenGLContext/cglContextObj) method. For more information on the underling CGL context, see `CGL`.

## Topics

### Creating Contexts

[`init(format:share:)`](/documentation/AppKit/NSOpenGLContext/init(format:share:))

Returns an OpenGL context object initialized with the specified pixel format information.

[`init(cglContextObj:)`](/documentation/AppKit/NSOpenGLContext/init(cglContextObj:)-30lqr)

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

### Managing the Current Context

[`clearCurrentContext()`](/documentation/AppKit/NSOpenGLContext/clearCurrentContext())

Clears the current context.

[`current`](/documentation/AppKit/NSOpenGLContext/current)

Returns the current OpenGL graphics context.

[`makeCurrentContext()`](/documentation/AppKit/NSOpenGLContext/makeCurrentContext())

Sets the context as the current OpenGL context object.

### Managing the Drawable Object

[`view`](/documentation/AppKit/NSOpenGLContext/view)

Returns the OpenGL context’s view.

[`setFullScreen`](/documentation/AppKit/NSOpenGLContext/setFullScreen)

Sets the OpenGL context to full-screen mode.

[`setOffScreen:width:height:rowbytes:`](/documentation/AppKit/NSOpenGLContext/setOffScreen:width:height:rowbytes:)

Instructs the OpenGL context to render into an offscreen buffer with the specified attributes.

[`clearDrawable()`](/documentation/AppKit/NSOpenGLContext/clearDrawable())

Disassociates the OpenGL context from its viewport.

[`update()`](/documentation/AppKit/NSOpenGLContext/update())

Updates the OpenGL context’s drawable object.

### Flushing the Drawing Buffer

[`flushBuffer()`](/documentation/AppKit/NSOpenGLContext/flushBuffer())

Copies the back buffer to the front buffer of the OpenGL context.

### Copying Attributes

[`copyAttributesFromContext:withMask:`](/documentation/AppKit/NSOpenGLContext/copyAttributesFromContext:withMask:)

Copies selected groups of state variables to the OpenGL context.

### Context Parameter Handling

[`setValues(_:for:)`](/documentation/AppKit/NSOpenGLContext/setValues(_:for:))

Sets the value of the specified parameter.

[`getValues(_:for:)`](/documentation/AppKit/NSOpenGLContext/getValues(_:for:))

Returns the value of the requested parameter.

### Working with Virtual Screens

[`currentVirtualScreen`](/documentation/AppKit/NSOpenGLContext/currentVirtualScreen)

Returns the current virtual screen for the OpenGL context.

### Creating Textures

[`createTexture:fromView:internalFormat:`](/documentation/AppKit/NSOpenGLContext/createTexture:fromView:internalFormat:)

Creates a new texture from the contents of the specified view.

### Getting the CGL Context Object

[`cglContextObj`](/documentation/AppKit/NSOpenGLContext/cglContextObj)

Returns the low-level, platform-specific Core OpenGL (CGL) context object represented by the receiver.

### Working with Pixel Buffers

[`setPixelBuffer:cubeMapFace:mipMapLevel:currentVirtualScreen:`](/documentation/AppKit/NSOpenGLContext/setPixelBuffer:cubeMapFace:mipMapLevel:currentVirtualScreen:)

Attaches the specified pixel buffer to the OpenGL context.

[`pixelBuffer`](/documentation/AppKit/NSOpenGLContext/pixelBuffer)

Returns the pixel-buffer object attached to the OpenGL context.

[`pixelBufferCubeMapFace`](/documentation/AppKit/NSOpenGLContext/pixelBufferCubeMapFace)

Returns the cube map face of the pixel buffer attached to the OpenGL context.

[`pixelBufferMipMapLevel`](/documentation/AppKit/NSOpenGLContext/pixelBufferMipMapLevel)

Returns the mipmap level of the pixel buffer attached to the OpenGL context.

[`setTextureImageToPixelBuffer:colorBuffer:`](/documentation/AppKit/NSOpenGLContext/setTextureImageToPixelBuffer:colorBuffer:)

Attaches the image data in the specified pixel buffer to the texture object currently bound by the OpenGL context.

### Getting the Pixel Format

[`pixelFormat`](/documentation/AppKit/NSOpenGLContext/pixelFormat)

The pixel format of the OpenGL context.

### Getting the OpenGL Version

[`openGLVersion`](/documentation/AppKit/NSOpenGLContext/openGLVersion)

The version of OpenGL.

### Constants

[`NSOpenGLContext.Parameter`](/documentation/AppKit/NSOpenGLContext/Parameter)

Constants that specify context parameters.



---

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)