<!--
{
  "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:sharegroup:)-2rt8m",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "OpenGL ES"
    ],
    "preciseIdentifier" : "c:objc(cs)EAGLContext(im)initWithAPI:sharegroup:"
  },
  "title" : "init(api:sharegroup:)"
}
-->

# init(api:sharegroup:)

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

```
init?(api: EAGLRenderingAPI, sharegroup: EAGLSharegroup)
```

## Parameters

`api`

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

`sharegroup`

A sharegroup obtained from another [`EAGLContext`](/documentation/OpenGLES/EAGLContext) object.

## 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 it the current drawing context by calling [`setCurrent(_:)`](/documentation/OpenGLES/EAGLContext/setCurrent(_:)).

OpenGL ES objects such as textures, renderbuffers, framebuffers and vertex buffers are shared across all contexts that are created with the same sharegroup. To specify that a new context should be initialized in an existing sharegroup, retrieve the [`sharegroup`](/documentation/OpenGLES/EAGLContext/sharegroup) property from a previously initialized context and pass it as a parameter to this initialization method. Pass `nil` as the `sharegroup` parameter to create a new [`EAGLSharegroup`](/documentation/OpenGLES/EAGLSharegroup) object attached to the context.

---

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)