Introduction to OpenGL ES
Android supports OpenGL ES for 3D rendering. OpenGL ES is a subset of the desktop OpenGL API implementation. On its own, Open Graphics Library (OpenGL) is a very popular cross-platform API for rendering 2D and 3D graphics.
It is slightly more complex to use OpenGL ES to render our custom view than the standard Android canvas drawing primitives and, as we'll see during this chapter, it needs to be used with common sense and it won't always be the best approach.
For any additional information about OpenGL ES please refer to the official documentation from The Khronos Group:https://www.khronos.org/opengles/.
Getting started with OpenGL ES in Android
It's very easy to create a 3D-enabled custom view. We can do it by simply extending GLSurfaceView
instead of just extending from the View
class. The complexity comes in the rendering part, but let's go step by step. First, we'll create a class named GLDrawer
and add it to our project:
package com.packt.rrafols.draw; import...