Game Development Reference
In-Depth Information
UV streams
When rendering a polygon with a texture, we need to somehow indicate how that
texture should be mapped to the polygon. We do this by specifying a UV stream that
allows us to state which part of the texture should appear at each vertex. The part of
the texture required for each rendered pixel can then be worked out by the rendering
engine by interpolating the UV values across the surface of the polygon.
In IwGx, UV coordinates are specified using floating point numbers. An individual
UV value is often written as (u, v) and is represented in IwGx using the CIwFVec2
class, which is a floating point equivalent of CIwSVec2 that we came across earlier.
The x component of the vector represents u , and the y component represents v .
UV values are mapped to a texture so that (0.0, 0.0) is the top left of the image
and (1.0, 1.0) is the bottom-right corner. We can repeatedly tile a texture up to a
maximum of eight times across our polygon by using values larger than one.
Prior to Marmalade version 6.1, UV values were given as 16-bit signed
integers using a 12-bit fixed point representation. The value 4096 is
equivalent to 1.0, 8192 is equivalent to 2.0, and 2048 is equivalent to 0.5.
The IwGeom API provides us with the define IW_GEOM_ONE , which
we can use to avoid having nasty-looking magic numbers throughout
our code. This functionality can still be used by reverting to the legacy
version of the IwGx API, as detailed earlier in this chapter.
By mapping UV values in this way, we make them independent of the actual size of
the texture image. If we change the size of the image for any reason, it won't mess up
rendering as our UV values do not need to change.
Search WWH ::




Custom Search