Graphics Programs Reference
Textures can be of two types—procedural textures and image textures. Procedural
textures are generated on the fly, based on some algorithm, whereas image textures,
as the name suggests, are textures loaded from image files, such as a .jpg , .png ,
and so on. This section demonstrates how to use image textures in ES 2.0.
Note Procedural and image textures are general classes of textures.
In ES 2.0, however, textures are of two types—2D textures and
Textures in OpenGL ES are 2D arrays of texture units known as texels . Similar to de-
fining geometry for primitives (using the Cartesian coordinates x, y, and z), to apply
texture(s) to a surface, specify the texture coordinates that correspond to the indices
into this texture array data. Unlike the coordinates for geometry, texture coordinates
use s and t (or u and v) as shown in Figure 5-2 . Since texture coordinate space is
normalized, both s and t range from 0 to 1. Please note that texture coordinates do
not have units, so as to make them independent of the dimensions of source image or
final rendered surface (composed of the texture).
Note The process that applies a texture to some geometric object is
called UV mapping.
To attach a 2D texture to a surface, we need to provide (s, t) coordinates from
this texture such that it can cover the surface. If the specified coordinates (from tex-
ture) do not fit the surface completely, we can use texture wrap modes (provided by
OpenGL ES) to help the textures wrap the surface, such as by repeating, mirroring, or
clamping themselves. As a beginner, you may find it difficult to deal with all of these
modes, so I shall only talk about the repeat wrap mode, defined as a static constant
GL_REPEAT in the android.opengl.GLES20 class. Now, I shall demonstrate
common uses of textures using ES 2.0.
Note In OpenGL ES 2.0, textures can have non-power-of-two
( npot ) dimensions. However, the support for such textures is still