Graphics Programs Reference
In-Depth Information
Figure 5-3 . Wrapping texture around a square object
Having read Table 5-1 , you should understand how texture coordinates have to be
mapped to vertex coordinates for a square object (or, in fact, any rectangular object).
Now, there are two important things to note here:
▪ When passing texture coordinates to a vertex shader, you do not
need to pass them separately for every primitive. Instead, pass
them the way you pass vertices. In the context of this example,
where you are wrapping a texture around a square object (or any
rectangular object), define a texture coordinate array with four
texture coordinates ( Listing 5-4 ), instead of six ( Table 5-1 ), simil-
ar to how you define a vertex coordinate array with four vertices,
as shown in Listing 5-4 .
Table 5-1 . Wrapping Texture on a Square Object: Specifying Texture
Coordinates
Position
Index
Vertex Coordinate
Texture Coordinate
top-right
2
(10, 10, 0)
(1, 1)
top-left
3
(-10, 10, 0)
(0, 1)
bottom-left
1
(-10, -10, 0)
(0, 0)
bottom-right
0
(10, -10, 0)
(1, 0)
top-right
2
(10, 10, 0)
(1, 1)
bottom-left
1
(-10, -10, 0)
(0, 0)
Listing
5-4. GL TEXTURE/src/com/apress/android/gltexture/GLES20Render-
er.java
 
 
 
Search WWH ::




Custom Search