Game Development Reference
In-Depth Information
Figure 7-9. Per-vertex colored triangle
Whoa, this is pretty neat! We didn't make any assumptions about how OpenGL ES will use the
three colors we specified (red for the bottom-left vertex, green for the bottom-right vertex, and
blue for the top vertex). It turns out that it will interpolate the colors between the vertices for us.
With this, we can easily create nice gradients.; however, colors alone will not make us happy for
very long. We want to draw images with OpenGL ES. And that's where texture mapping comes
into play.
Texture Mapping: Wallpapering Made Easy
When we wrote Mr. Nom, we loaded some bitmaps and directly drew them to the framebuffer—
no rotation involved, just a little bit of scaling, which is pretty easy to achieve. In OpenGL ES, we
are mostly concerned with triangles, which can have any orientation or scale we want them to
have. So, how can we render bitmaps with OpenGL ES?
Easy, just load up the bitmap to OpenGL ES (and for that matter, to the GPU, which has its own
dedicated RAM), add a new attribute to each of our triangle's vertices, and tell OpenGL ES to
render our triangle and apply the bitmap (also known as texture in OpenGL ES speak) to the
triangle. Let's first look at what these new vertex attributes actually specify.
Texture Coordinates
To map a bitmap to a triangle, we need to add texture coordinates to each vertex of the triangle.
What is a texture coordinate? It specifies a point within the texture (our uploaded bitmap) to be
mapped to one of the triangle's vertices. Texture coordinates are usually 2D.
 
Search WWH ::




Custom Search