## The Rendering Pipeline

OpenGL ES keeps track of these three matrices. Each time we set one of the matrices, it will remember it until we change the matrix again. In OpenGL ES speak, this is called a state. OpenGL keeps track of more than just the matrix states, though; it also keeps track of whether we want it to alpha-blend triangles, whether we want lighting to be taken into account, which texture should be applied to our geometry, and so on. In fact, OpenGL ES is one huge state machine. We set its current state, feed it the geometries of our objects, and tell it to render an image for us. Let's see how a triangle passes through this mighty triangle-rendering machine. Figure 7-4 shows a very high-level, simplified view of the OpenGL ES pipeline:

The way of the a triangle through this pipeline looks as follows:

1. Our brave triangle is first transformed by the model-view matrix. This means that all its points are multiplied with this matrix. This multiplication will effectively move the triangle's points around in the world.

2. The output of this is then multiplied by the projection matrix, effectively transforming the 3D points onto the 2D projection plane.

3. In between these two steps (or parallel to them), the currently set lights and materials are also applied to our triangle, giving it its color.

4. Once all that is done, the projected triangle is clipped to our "retina" and transformed to framebuffer coordinates.

5. As a final step, OpenGL fills in the pixels of the triangle based on the colors from the lighting stage, textures to be applied to the triangle, and the blending state, in which each pixel of the triangle might or might not be combined with the pixel in the framebuffer.

All we need to learn is how to throw geometry and textures at OpenGL ES, and set the states used by each of the preceding steps. Before we can do that, though, we need to check out how Android grants us access to OpenGL ES.

NOTE: While the high-level description of the OpenGL ES pipeline is mostly correct, it is heavily simplified and leaves out some details that will become important in a later chapter. Another thing to note is that when OpenGL ES performs projections, it doesn't actually project onto a 2D coordinate system. Instead it projects into something called a homogenous coordinate system, which is actually four dimensional. This is a very involved mathematical topic, so for the sake of simplicity, we'll just stick to the simplified belief that OpenGL ES projects to 2D coordinates.

## Post a comment