Setting up GLSurfaceView and OpenGL ES 2.0

suggest change

To use OpenGL ES in your application you must add this to the manifest:

<uses-feature android:glEsVersion="0x00020000" android:required="true"/>

Create your extended GLSurfaceView:

import static android.opengl.GLES20.*; // To use all OpenGL ES 2.0 methods and constants statically

public class MyGLSurfaceView extends GLSurfaceView {
    public MyGLSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);

        setEGLContextClientVersion(2); // OpenGL ES version 2.0
        setRenderer(new MyRenderer());

    public final class MyRenderer implements GLSurfaceView.Renderer{
        public final void onSurfaceCreated(GL10 unused, EGLConfig config) {
            // Your OpenGL ES init methods
            glClearColor(1f, 0f, 0f, 1f);
        public final void onSurfaceChanged(GL10 unused, int width, int height) {
            glViewport(0, 0, width, height);

        public final void onDrawFrame(GL10 unused) {
            // Your OpenGL ES draw methods

Add MyGLSurfaceView to your layout:


To use newer version of OpenGL ES just change the version number in your manifest, in the static import and change setEGLContextClientVersion.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents