Game Development Reference
In-Depth Information
Orthographic Projection with glOrthof
OpenGL ES offers the following method for setting the active matrix to an orthographic (parallel)
projection matrix:
GL10.glOrthof( int left, int right, int bottom, int top, int near, int far)
Hey, that looks like it has something to do with our view frustum's clipping planes . . . and indeed
it does! So what values do we specify here?
OpenGL ES has a standard coordinate system, as depicted in Figure 7-5 . The positive x axis
points to the right, the positive y axis points upward, and the positive z axis points toward us.
With glOrthof() , we define the view frustum of our parallel projection in this coordinate system.
If you look back at Figure 7-3 , you can see that the view frustum of a parallel projection is a box.
We can interpret the parameters for glOrthof() as specifying two of these corners of our view
frustum box. Figure 7-5 illustrates this.
Figure 7-5. An orthographic view frustum
The front side of our view frustum will be directly mapped to our viewport. In the case of a
full-screen viewport from, say, (0,0) to (480,320) (for example, landscape mode on a Hero), the
bottom-left corner of the front side would map to the bottom-left corner of our screen, and the
top-right corner of the front side would map to the top-left corner of our screen. OpenGL will
perform the stretching automatically for us.
Since we want to do 2D graphics, we will specify the corner points—left, bottom, near, and right,
top, far (see Figure 7-5 )—in a way that allows us to work in a sort of pixel coordinate system, as
we did with the Canvas and Mr. Nom. Here's how we could set up such a coordinate system:
gl.glOrthof(0, 480, 0, 320, 1, -1);
Figure 7-6 shows the view frustum.
 
Search WWH ::




Custom Search