Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

# GLSurfaceView.Renderer

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/opengl/GLSurfaceView.Renderer "View this page in Kotlin") \|Java


`
public
static


interface
GLSurfaceView.Renderer
`


`


`

|---|
| android.opengl.GLSurfaceView.Renderer |

<br />

*** ** * ** ***

A generic renderer interface.


The renderer is responsible for making OpenGL calls to render a frame.


GLSurfaceView clients typically create their own classes that implement
this interface, and then call `https://developer.android.com/reference/android/opengl/GLSurfaceView#setRenderer(android.opengl.GLSurfaceView.Renderer)` to
register the renderer with the GLSurfaceView.


### Developer Guides

For more information about how to use OpenGL, read the
[OpenGL](https://developer.android.com/guide/topics/graphics/opengl) developer guide.

### Threading

The renderer will be called on a separate thread, so that rendering performance is decoupled from the UI thread. Clients typically need to communicate with the renderer from the UI thread, because that's where input events are received. Clients can communicate using any of the standard Java techniques for cross-thread communication, or they can use the `https://developer.android.com/reference/android/opengl/GLSurfaceView#queueEvent(java.lang.Runnable)` convenience method.


### EGL Context Lost

There are situations where the EGL rendering context will be lost. This typically happens when device wakes up after going to sleep. When the EGL context is lost, all OpenGL resources (such as textures) that are associated with that context will be automatically deleted. In order to keep rendering correctly, a renderer must recreate any lost resources that it still needs. The `https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer#onSurfaceCreated(javax.microedition.khronos.opengles.GL10,%20javax.microedition.khronos.egl.EGLConfig)` method is a convenient place to do this.

<br />

**See also:**

- `https://developer.android.com/reference/android/opengl/GLSurfaceView#setRenderer(android.opengl.GLSurfaceView.Renderer)`

## Summary

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer#onDrawFrame(javax.microedition.khronos.opengles.GL10)(https://developer.android.com/reference/javax/microedition/khronos/opengles/GL10 gl) ` Called to draw the current frame. |
| ` abstract void` | ` https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer#onSurfaceChanged(javax.microedition.khronos.opengles.GL10,%20int,%20int)(https://developer.android.com/reference/javax/microedition/khronos/opengles/GL10 gl, int width, int height) ` Called when the surface changed size. |
| ` abstract void` | ` https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer#onSurfaceCreated(javax.microedition.khronos.opengles.GL10,%20javax.microedition.khronos.egl.EGLConfig)(https://developer.android.com/reference/javax/microedition/khronos/opengles/GL10 gl, https://developer.android.com/reference/javax/microedition/khronos/egl/EGLConfig config) ` Called when the surface is created or recreated. |

## Public methods

### onDrawFrame

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onDrawFrame (GL10 gl)
```

Called to draw the current frame.


This method is responsible for drawing the current frame.


The implementation of this method typically looks like this:

```scdoc
 void onDrawFrame(GL10 gl) {
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
     //... other gl calls to render the scene ...
 }
 
```

<br />

<br />

| Parameters ||
|---|---|
| `gl` | `GL10`: the GL interface. Use `instanceof` to test if the interface supports GL11 or higher interfaces. <br /> |

### onSurfaceChanged

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onSurfaceChanged (GL10 gl, 
                int width, 
                int height)
```

Called when the surface changed size.


Called after the surface is created and whenever
the OpenGL ES surface size changes.


Typically you will set your viewport here. If your camera
is fixed then you could also set your projection matrix here:

```povray
 void onSurfaceChanged(GL10 gl, int width, int height) {
     gl.glViewport(0, 0, width, height);
     // for a fixed camera, set the projection too
     float ratio = (float) width / height;
     gl.glMatrixMode(GL10.GL_PROJECTION);
     gl.glLoadIdentity();
     gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
 }
 
```

<br />

<br />

| Parameters ||
|---|---|
| `gl` | `GL10`: the GL interface. Use `instanceof` to test if the interface supports GL11 or higher interfaces. <br /> |

### onSurfaceCreated

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void onSurfaceCreated (GL10 gl, 
                EGLConfig config)
```

Called when the surface is created or recreated.


Called when the rendering thread
starts and whenever the EGL context is lost. The EGL context will typically
be lost when the Android device awakes after going to sleep.


Since this method is called at the beginning of rendering, as well as
every time the EGL context is lost, this method is a convenient place to put
code to create resources that need to be created when the rendering
starts, and that need to be recreated when the EGL context is lost.
Textures are an example of a resource that you might want to create
here.


Note that when the EGL context is lost, all OpenGL resources associated
with that context will be automatically deleted. You do not need to call
the corresponding "glDelete" methods such as glDeleteTextures to
manually delete these lost resources.

<br />

<br />

| Parameters ||
|---|---|
| `gl` | `GL10`: the GL interface. Use `instanceof` to test if the interface supports GL11 or higher interfaces. <br /> |
| `config` | `EGLConfig`: the EGLConfig of the created surface. Can be used to create matching pbuffers. <br /> |