2009. 10. 23. 14:27

Android & OpenGL ES

Here, we will talk about working with the OpenGL graphics API on the Android Platform.
Specifically, we’ll break down the topic into three sections.
First, we’ll provide an overview of OpenGL, OpenGL for Embedded Systems (OpenGL ES), and some competing standards.
Second, we will explain the theory behind OpenGL and cover some of the essential OpenGL ES APIs.
Third and final section, we will give you the necessary code to build a test harness that you can use to exercise the APIs covered in the second section.

Understanding OpenGL;OpenGL ES;OpenGL ES and Java ME

M3G: Another Java ME 3D Graphics Standard
JSR 239 is merely a Java binding on a native OpenGL ES standard. As we mentioned briefly in
the “OpenGL ES” subsection, Java provides another API to work with 3D graphics on mobile
devices: M3G. This object-oriented standard is defined in JSR 184 and JSR 297, the latter being
more recent. As per JSR 184, M3G serves as a lightweight, object-oriented, interactive 3D
graphics API for mobile devices.

M3G is a higher-level API compared to OpenGL ES, so it should be easier to learn. However,
the jury is still out on how well it will perform on handhelds. As of now, Android does not
support M3G.

Using OpenGL ES
• glVertexPointer
• glDrawElements
• glColor
• glClear
• gluLookAt
• glFrustum
• glViewport

As we cover these APIs, you’ll learn how to
• Use the essential OpenGL ES drawing APIs
• Clear the palette
• Specify colors
• Understand the camera and coordinates
• Interact with an Android view to draw using OpenGL ES

OpenGL ES offers two primary methods to facilitate drawing:
• glVertexPointer
• glDrawElements

Understanding the Camera and Coordinates
• gluLookAt: Controls the direction of the camera
• glFrustum: Controls the viewing volume or zoom
• glViewport: Controls the size of the screen or the size of the camera’s “film”


Interfacing OpenGL ES with Android
• Getting an EGL context
• Associating a drawing surface with OpenGL ES through the EGL context
• Disassociating the drawing surface from the EGL context and closing out the OpenGL ES resources

Creating and Using the OpenGL Test Harness & APIDemos OpenGL ES
 
......

Summary
Here, we covered the basics of OpenGL support in Android. We provided resources
to help you learn more about OpenGL, and we explored how Android uses OpenGL ES from
its SDK. You should now have enough background to work with the OpenGL samples that ship
with the Android SDK. We also gave you a convenient, simplified test harness that you can use
to explore OpenGL further. After experimenting with the samples and the test harness, you
should be ready for advanced development with Android and OpenGL.