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:

update(float deltaTime) {

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 zero and width and height to our screen resolution, as we are using full-screen mode. We could instruct OpenGL ES to only use 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.

Was this article helpful?

0 0

Post a comment