---
title: "texture(with:options:)"
framework: glkit
role: symbol
role_heading: Type Method
path: "glkit/glktextureloader/texture(with:options:)"
---

# texture(with:options:)

Loads a 2D texture image from a Quartz image and creates a new texture from the data.

## Declaration

```swift
class func texture(with cgImage: CGImage, options: [String : NSNumber]? = nil) throws -> GLKTextureInfo
```

## Parameters

- `cgImage`: The Quartz image to be turned into a texture.
- `options`: A dictionary that describes any additional steps you want the texture loader to take when loading the texture. See doc://com.apple.glkit/documentation/GLKit/texture-loading-options.

## Return Value

Return Value A texture info object that describes the loaded texture or nil if an error occurred.

## Discussion

Discussion This class method loads the texture into the sharegroup attached to the current context for the thread this method is called on. If the image was created using the CGBitmapImageContextCreate function, it must use one of the pixel formats described in the table below. CGImages loaded from files typically are already in one of these formats.  |   |   |   |   |   |  note: In Swift, this method returns a nonoptional result and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Creating Textures from CGImages

- [texture(with:options:queue:completionHandler:)](glkit/glktextureloader/texture(with:options:queue:completionhandler:).md)
