Game Development Reference
In-Depth Information
Defining the Viewport
OpenGL ES uses the viewport as a way to translate the coordinates of points projected to
the near clipping plane to framebuffer pixel coordinates. We can tell OpenGL ES to use only a
portion of our framebuffer—or all of it—with the following method:
GL10.glViewport( int x, int y, int width, int height)
The x and y coordinates specify the top-left corner of the viewport in the framebuffer, and width
and height specify the viewport's size in pixels. Note that OpenGL ES assumes the framebuffer
coordinate system to have its origin in the lower left of the screen. Usually we set x and y to 0
and width and height to our screen resolution, as we are using full-screen mode. We could
instruct OpenGL ES to use only a portion of the framebuffer with this method. It would then take
the rendering output and automatically stretch it to that portion.
Note While this method looks like it sets up a 2D coordinate system for us to render to, it actually
does not. It only defines the portion of the framebuffer OpenGL ES uses to output the final image.
Our coordinate system is defined via the projection and model-view matrices.
Defining the Projection Matrix
The next thing we need to define is the projection matrix. As we are only concerned with
2D graphics in this chapter, we want to use a parallel projection. How do we do that?
Matrix Modes and Active Matrices
We already discussed that OpenGL ES keeps track of three matrices: the projection matrix, the
model-view matrix, and the texture matrix (which we'll continue to ignore). OpenGL ES offers
several specific methods to modify these matrices. Before we can use these methods, however,
we have to tell OpenGL ES which matrix we want to manipulate. We do so with the following
method:
GL10.glMatrixMode( int mode)
The mode parameter can be GL10.GL_PROJECTION , GL10.GL_MODELVIEW , or GL10.GL_TEXTURE .
It should be clear which of these constants will make which matrix active. Any subsequent
calls to the matrix manipulation methods will target the matrix we set with this method until
we change the active matrix again via another call to this method. This matrix mode is one of
OpenGL ES's states (which will get lost when we lose the context if our application is paused
and resumed). To manipulate the projection matrix with any subsequent calls, we can call the
method like this:
gl.glMatrixMode(GL10.GL_PROJECTION);
 
 
Search WWH ::




Custom Search