<!--
{
  "availability" : [
    "iOS: 2.0.0 - 12.0.0",
    "iPadOS: 2.0.0 - 12.0.0",
    "macCatalyst: 2.0.0 - 12.0.0",
    "tvOS: 9.0.0 - 12.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "OpenGLES",
  "identifier" : "/documentation/OpenGLES/EAGLContext/init(api:)-q09o",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "OpenGL ES"
    ],
    "preciseIdentifier" : "c:objc(cs)EAGLContext(im)initWithAPI:"
  },
  "title" : "init(api:)"
}
-->

# init(api:)

Initializes and returns a newly allocated rendering context with the specified version of the OpenGL ES rendering API.

```
convenience init?(api: EAGLRenderingAPI)
```

## Parameters

`api`

The desired version of the OpenGL ES rendering API. For legal values, see [`EAGLRenderingAPI`](/documentation/OpenGLES/EAGLRenderingAPI).

## Return Value

An initialized context object, or `nil` if the object couldn’t be created.

## Discussion

To issue OpenGL ES commands to this context, you must first make the context current by calling [`setCurrent(_:)`](/documentation/OpenGLES/EAGLContext/setCurrent(_:)).

Calling [`init(api:)`](/documentation/OpenGLES/EAGLContext/init(api:)-q09o) creates a new [`EAGLSharegroup`](/documentation/OpenGLES/EAGLSharegroup) object and attaches it to this context.

## See Also

  [OpenGL ES Programming Guide](https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008793)



---

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)