An Introduction to OpenGL for the Google Android Programming Environment

Article by Jbeer (2,327 pts ) , published Apr 16, 2009

Google Android platform supports OpenGL ES 1.0 (and some functionality of versions 1.1). OpenGL is a graphic library focused on 3D graphics.

Introduction

In this article, we will introduce a bit about OpenGL and its integration in Android. Lets talk about OpenGL.

OpenGL, as I mentioned before, Is a graphics library, that helps us to create 2D and 3D environments. This library, opposite to Direct3D from Microsoft, is multiplatform in that you can create applications that use OpenGL in a GNU/Linux system and in a Windows one.

In mobile devices we have a reduced version: OpenGL ES. It has less functionality that OpenGL (without ES) and it's adapted to small devices with their limitations. In an Android phone we don't have great graphics cards, so resources and implementation has to be optimized if we want to achieve good results.

In the Khronos page we can find a lot of information about this technology.

http://www.khronos.org/opengles/

OpenGL ES in Android

Android currently supports OpenGL ES 1.0, which corresponds to OpenGL 1.3 on a desktop system. The API we use to develop in Android is very similar to the J2ME OpenGL ES API (JSR 239). The OpenGL ES libraries and functionality can be found in the following packages:

javax.microedition.khronos.opengles

javax.microedition.khronos.egl

android.opengl

How to use the API

When I work with OpengGL I always use a “template” get from Android OpenGL examples. It's a pseudo API that helps me to forget about how Android handles OpenGL and focus on implementation.

One of the main classes to handle OpenGL is GLSurfaceView

http://developer.android.com/guide/samples/ApiDemos/src/com/example/android/apis/graphics/GLSurfaceView.html

Then we have to create a class that implements the interface GLSurfaceView.Renderer. In further lessons I will explain a bit deeper about this class, for now, we need to know that:

  • In this class we initialize and specify the parameters of the OpenGL environment.
  • Here is the “draw” method. This function is always drawing, so code we put inside will be constantly drawn in the screen. If we are drawing a cube that moves in the screen, this is the place to put the routines that are going to drive the cube movement.
  • Other interesting method is the “surfaceCreated” method. This is called the first time, when the application is launched. Here we define the parameters of the OpenGL that are going to be rules, we can ever create another class to load Textures.

Some Terminology

Talking this way about OpenGL and Android could be a bit shocking for people that have no idea of what OpenGL is. For making things more easily understood, let's define some terms to clarify these ideas.

SurfaceView: Provides a dedicated drawing surface embedded inside of a view hierarchy. With this we can create OpenGL objects over views and layouts. This is like the canvas we are going to use to draw our OpenGL environment.

SurfaceHolder. A client may implement this interface to receive information about changes to the surface

GL10. Its an interface that implements the GL “object”. We will use this GL object to work with the OpenGL routines

Textures. The textures are images we can add to a OpenGL object.

Want more?

I know this can be confusing as It's not a easy subject, however I will try to do my best to help you to understand it. In future articles we'll examine OpenGL step by step. Stay tuned!

Comments

Sep 25, 2009 3:45 AM
Open GL to draw an image of a desktop
Hi Neer

Ummmm. Its quite difficult for me to say you something helpfull. But you should take account that:

The phones have about 528 MHz of proccess frequency. Between 192 and 256 Mbs of RAM (Depending on the model). And I think that no such a thing like a "graphic card".

I dont know how complex is the 3D desktop you want to show, I have worked with OpenGL in a very basic examples (Also with images on top of openGL objects).

Anyway, Android is surprising me everyday, so, I suggest you to go on with your project and find out if such a thing you tell me can be done. And please, I would like to know more about the progress of the project. It seems interesting to me. My personal email is :

jbeerbros (at) gmail.com

Sep 24, 2009 10:49 AM
Neer
Open GL to draw an image of a desktop
Hello Jbeer,

I am from India. Actually i am building an app for Android which talks Remote Desktop Protocol (RDP). There is a graphics acceleration extension to this RDP.

In ordinary RDP clients, the BITMAP image sent by the RDP server is displayed on the screen.

However in this graphics acceleration extn the server sends DRAWING INSTRUCTIONS. We want to draw the bitmap image using OpenGL by following the instructions.

So do you think it is possible to draw an image of a desktop using open GL??

If yes, will it eat up too much memory and ARM processor cycles?

Will it slow down the app miserably?
Sep 24, 2009 2:24 AM
Jbeer
Hi Bharath.

OpenGL ES in Android is not an easy stuff. I have worked with it some time ago, anyway, I will write about it as soon as I can. About the updates, maybe you can subscribe using the RSS.
Sep 15, 2009 12:42 PM
Bharath
Very Intresting
I would like to receive all future updates about Open GL ES.