Graphics Programs Reference
In-Depth Information
limited to some devices. So, for all the applications in the source
code in which we have demonstrated the use of textures, we have
only used textures with power-of-two dimensions.
2D Texture
First, let's look at defining texture coordinates. Consider an example in which we
wrap a texture around a square object. As shown in Figure 5-2 , the bottom-left and
top-right corners of the texture (image) are specified by (s, t) coordinates as (0,
0) and (1, 1) , respectively. If the specified (s, t) coordinate is outside the
range [0, 1] , you can specify texture wrap mode, independently for both the s-co-
ordinate and t-coordinate. Using wrap mode GL_REPEAT , texture outside this range
is simply repeated.
Figure 5-2 . Texture coordinate space: 64x64 texture
This square can be rendered using triangle primitives, as shown in Figure 5-3 . Sup-
pose we use glDrawElements to render it. The short array planeISA in List-
ing 5-4 consists of one of the ways to specify the indices, to access vertices from
planeVFA vertex array (to render this square). To wrap texture around this square,
when vertices are fetched using index array planeISA , texture coordinates must
also be fetched. To make sure that texture coordinates are fetched in the same order
as that of the vertices, you need to understand the sequence shown in Table 5-1 .
Search WWH ::

Custom Search