In this chapter I introduce you to OpenGL ES 2.0, and account for its increasing popularity compared to older graphic rendering APIs for embedded devices. I describe OpenGL ES 2.0s support from computer-graphics communities and leading embedded and mobile device vendors, which helps to ensure its increasing popularity. Finally, I show how easy it is to get started with ES 2.0 on Android devices, when we take our first step towards game development, by creating a blank OpenGL surface view.
This chapter assumes you have some experience of setting up Android Software Development Kit (SDK) for Eclipse and installing SDK Platform for various API levels from SDK Manager.
Modern Graphic-rendering API
OpenGL ES (Open Graphics Library for Embedded Systems) is an API (Application Programming Interface) for rendering 3D graphics on embedded devices, such as mobiles, tablets, and gaming consoles.
The OpenGL ES 1.0 and ES 1.1 APIs (referred to jointly as OpenGL ES 1.x) were released by the non-profit Khronos Group as a fixed-function graphic-rendering API. OpenGL ES 1.x API does not provide graphics application developers full access to underlying hardware, because most rendering functions in this API are hard-coded, leading to popular namesfixed-function graphic rendering API or fixed-function pipeline.
Unlike OpenGL ES 1.x API, OpenGL ES 2.0 API was released as a programmable graphic-rendering API (programmable pipeline), giving developers full access to the underlying hardware through shaders (discussed in ).
Graphics rendered through a fixed-function pipeline involve device-provided algorithms for most rendering effects. These algorithms (and the rendering functions based on them) cannot be modified. They are fixed because they were made for special purpose graphics cards, for a specific data-flow. Because of the fixed functionality of OpenGL ES 1.x API, graphics hardware could be optimized for faster rendering.
In contrast, a programmable graphic-rendering API is a more flexible API and requires a general purpose graphics card, enabling graphic developers to unleash the huge potential of modern GPUs. Technically, the programmable pipeline is slower than the fixed function pipeline; however, graphics rendered using the programmable pipeline can be greatly enhanced because of flexibility offered by new general purpose graphics cards. OpenGL ES 2.0 combines GLSL ( OpenGL Shading Language ) with a modified subset of OpenGL ES 1.1 that has removed any fixed functionality. discusses OpenGL Shading Language.
Note
GLSL is the OpenGL Shading Language for programming vertex and fragment shaders. Shaders are programs in programmable pipelines that help users work on two separate aspects of object rendering: vertex marking and color filling.
With OpenGL ES 2.0, enhancements in various effects, such as lighting/shading effects (as shown in Figure a basic shading example), no longer have any restrictions, compared to ES 1.x. What is required is transformation of creative ideas for any such effects into algorithms, then into custom functions executed on the graphics card, which would be impossible in ES 1.x.
Figure 1-1.
ADS (Ambient Diffuse Specular) shading in OpenGL ES 2.0
OpenGL ES 2.0 is derived from the larger OpenGL 2.0 API, the programmable pipeline for rendering 3D graphics on desktops. ES 2.0 is a suitable subset of OpenGL, optimized for resource constrained display devices, such as mobiles, tablets, and gaming consoles. ES 2.0 contains only the most useful methods from OpenGL 2.0 API, with redundant techniques removed. This allows OpenGL ES 2.0 on handheld devices to deliver rich game content like its parent API.
Devices Love It
As of October 1, 2012, more than 90% of all Android devices were running version 2.0 of OpenGL ES. Devices running version 2.0 are also capable of emulating version 1.1. However, an activity in Android cannot use both versions together, stemming from the fact that OpenGL ES 2.0 API is not backwards compatible with ES 1.x. Note that, although an activity cannot use both versions together, an application can still use them together. (Information about OpenGL ES version distribution across Android devices is available at shows a chart representing that distribution.)
Note
To demonstrate the use of both ES 1.x and ES 2.0 APIs in an application, the GLES ACTIVITY application is provided in the source code for this chapter. This application contains activities Main and Second . The Main activity uses ES 1.x, whereas the Second activity uses ES 2.0. To load this application into your Eclipse workspace, under File Menu, select Import, and then import the archive file glesactivity.zip from the Chapter1 folder.
Figure 1-2.
OpenGL ES version distribution
OpenGL ES 2.0 constitutes such a huge share of distribution (Figure .) The following vendors have actively participated in consolidating support for OpenGL ES 2.0 on Android since 2010:
(Leading GPU manufacturers)
NVIDIA
AMD
Imagination Technologies
(Leading CPU manufacturers)
ARM
Texas Instruments
STMicroelectronics
Implementer companies make use of the Khronos developed technologies at no cost in license fees. However, they do not claim that a product is compliant, unless the technologies enter and pass conformance testing. The following are the implementers of OpenGL ES 2.0 for various embedded devices:
Note
Although most embedded platforms are up and running with OpenGL ES 2.0, the Khronos Group announced on August 6th, 2012, the release of the OpenGL ES 3.0 specification, bringing significant functionality and portability enhancements to OpenGL ES API. OpenGL ES 3.0 is backwards compatible with OpenGL ES 2.0, enabling applications to incrementally add new visual features to applications. The full specification and reference materials are available for immediate download at http://www.khronos.org/registry/gles/ .
Easy App Development: Lets Create an OpenGL Surface View
ES 2.0 applications can be easily developed for Android devices using the Android SDK. The best part about creating such applications using this SDK is that there is no need for any external library (something that can be quite burdensome for new ES 2.0 application developers on iPhone).