OpenGL ES rendering example

This is an example of how to perform OpenGL ES rendering on Android. OpenGL for Embedded Systems (OpenGL ES) is a subset of the OpenGL 3D graphics application programming interface (API) designed for embedded systems such as mobile phones, PDAs, and video game consoles.

OpenGL ES rendering can be done following these steps:

  • Create a class that extends Activity
  • Create an instance of the GLSurfaceView class
  • Create a new GlRenderer for the GLSurfaceView class
  • The GlRenderer should implement the Renderer interface
  • Implement the onDrawFrame, onSurfaceChanged and onSurfaceCreated methods

These are demonstrated in the code snippet(s) below:

package net.obviam.opengl;

import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class Run extends Activity {

	/** The OpenGL view */
	private GLSurfaceView glSurfaceView;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {


  // requesting to turn the title OFF


  // making it full screen

  // Initiate the Open GL view and

  // create an instance with this activity

  glSurfaceView = new GLSurfaceView(this);

  // set our renderer to be the main renderer with

  // the current activity context

  glSurfaceView.setRenderer(new GlRenderer());


	/** Remember to resume the glSurface  */
	protected void onResume() {

	/** Also pause the glSurface  */
	protected void onPause() {
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView.Renderer;

public class GlRenderer implements Renderer {

	public void onDrawFrame(GL10 gl) {

	public void onSurfaceChanged(GL10 gl, int width, int height) {

	public void onSurfaceCreated(GL10 gl, EGLConfig config) {

This was an example of how to perform OpenGL ES rendering with Android.

Related Article:

Reference: OpenGL ES with Android Tutorial- Switching from Canvas to OpenGL from our JCG partner Tamas Jano at the “Against The Grain” blog.

Want to know how to develop your skillset to become a Java Rockstar?

Join our newsletter to start rocking!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design


and many more ....


Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions


Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Back to top button