Graphics Programs Reference
In-Depth Information
float[] planeVFA = {
10.000000f,-10.000000f,0.000000f, // bottom-right
-10.000000f,-10.000000f,0.000000f, // bottom-left
10.000000f,10.000000f,0.000000f, // top-right
-10.000000f,10.000000f,0.000000f, // top-left
};
float[] planeTFA = { // texture coordinate array
// 1,0, 0,0, 1,1, 0,1
1,1, 0,1, 1,0, 0,0
};
short[] planeISA = {
2,3,1, // top-right, top-left, bottom-left
0,2,1, // bottom-right, top-right, bottom-left
};
▪ Android uses the top-left corner as (0, 0) of the texture co-
ordinate space, whereas OpenGL uses the bottom-left corner as
(0, 0) , which is why you must vertically flip the texture co-
ordinates specified in the texture coordinate array. Therefore, (1,
0) becomes (1, 1) , and (1, 1) becomes (1, 0) , and so
on.
Loading the Image Data
Using a texture in ES 2.0 first requires you to create a texture object. This texture
object is represented by an unsigned integer (texture id), which is a reference to
the texture object. The ES 2.0 function used to generate texture objects is called
glGenTextures . In Android (SDK), it is accessed as the
GLES20.glGenTextures method. This method has two overloaded versions.
The one we use takes three arguments. In the first argument, specify the number of
texture objects to be generated. Wrapping a single texture around a square only re-
quires one texture object. The second argument is the array that will store the re-
turned texture ids, referencing texture objects. To generate a single texture object,
this array must be at least of size one, as shown in Listing 5-5 ( int array tex-
tures ). The last argument is the offset, and we will set this to “0”.
 
Search WWH ::




Custom Search