OpenGL ES
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.app.Activity;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. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // requesting to turn the title OFF requestWindowFeature(Window.FEATURE_NO_TITLE); // making it full screengetWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); // 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()); setContentView(glSurfaceView); }/** Remember to resume the glSurface */@Overrideprotected void onResume() {super.onResume();glSurfaceView.onResume();}/** Also pause the glSurface */@Overrideprotected void onPause() {super.onPause();glSurfaceView.onPause();}}import javax.microedition.khronos.egl.EGLConfig;import javax.microedition.khronos.opengles.GL10;import android.opengl.GLSurfaceView.Renderer;public class GlRenderer implements Renderer {@Overridepublic void onDrawFrame(GL10 gl) {}@Overridepublic void onSurfaceChanged(GL10 gl, int width, int height) {}@Overridepublic 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 ourJCG partner Tamas Jano at the“Against The Grain” blog.
Do you want to know how to develop your skillset to become aJava Rockstar?
Subscribe to our newsletter to start Rockingright now!
To get you started we give you our best selling eBooks forFREE!
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 ....
I agree to theTerms andPrivacy Policy

Thank you!
We will contact you soon.
Ilias Tsagklis
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor atJava Code Geeks.



