Applying Projection and Camera View while drawing

As we saw in the previous recipe, when we draw our shape to the screen, the shape is skewed by the screen orientation. The reason for this is because, by default, OpenGL assumes a perfectly square screen. We mentioned before, the default screen coordinates for the top right is (1,1,0) and bottom left is (-1,-1,0).

Since most device screens are not perfectly square, we need to map the display coordinates to match our physical device. In OpenGL, we do this with Projection. This recipe will show how to use Projection to match the GLSurfaceView coordinates with the device coordinates. Along with the Projection, we'll also show how to set the Camera View. Here's a screenshot showing the final result: ...

Get Android Application Development Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.