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:
Getting ready
Create a new project in Android Studio and call it: ProjectionAndCamera
. Use the default Phone & Tablet options and select Empty Activity when prompted for Activity Type.
This recipe builds on the previous recipe Drawing shapes on the...