Game Development Reference
In-Depth Information
While we call our positional coordinates x, y, and z, texture coordinates are usually called u and v
or s and t, depending on the circle of graphics programmers of which you're a member. OpenGL
ES calls them s and t, so that's what we'll stick to. If you read resources on the Web that use the
u/v nomenclature, don't get confused: it's the same as s and t. What does the coordinate system
look like? Figure 7-10 shows Bob in the texture coordinate system after we uploaded him to
OpenGL ES.
Figure 7-10. Bob, uploaded to OpenGL ES, shown in the texture coordinate system
There are a couple of interesting things going on here. First of all, s equals the x coordinate in
a standard coordinate system, and t is equal to the y coordinate. The s axis points to the right,
and the t axis points downward. The origin of the coordinate system coincides with the top-left
corner of Bob's image. The bottom-right corner of the image maps to (1,1).
So, what happened to pixel coordinates? It turns out that OpenGL ES doesn't like them a lot.
Instead, any image we upload, no matter its width and height in pixels, will be embedded into
this coordinate system. The top-left corner of the image will always be at (0,0), and the bottom-
right corner will always be at (1,1)—even if, say, the width is twice as large as the height. We call
these normalized coordinates , and they actually make our lives easier at times. Now, how can we
map Bob to our triangle? Easy, we just give each vertex of the triangle a texture coordinate pair
in Bob's coordinate system. Figure 7-11 shows a few configurations.
Figure 7-11. Three different triangles mapped to Bob; the names v1, v2, and v3 each specify a vertex of the triangle
We can map our triangle's vertices to the texture coordinate system however we want. Note that
the orientation of the triangle in the positional coordinate system does not have to be the same
Search WWH ::




Custom Search