Android OpenGL ES Development (1): Introduction to OpenGL ES

Introduction to OpenGL ES

Speaking of OpenGL ES, we should first understand the basic architecture of Android. The basic architecture is as follows:

Here we can find the libraries we are currently in contact with in Libraries, namely OpenGL ES.

According to the above figure, it can be known that Android currently supports the use of open graphics libraries, especially through the OpenGL ES API to support high-performance 2D and 3D graphics. OpenGL is a cross-platform graphics API. A standard software interface is specified for 3D graphics processing hardware. OpenGL ES is an OpenGL specification for embedded devices.

The detailed status of Android supporting OpenGL ES API version is:

  • OpenGL ES 1.0 and 1.1 can be supported by Android 1.0 and above
  • OpenGL ES 2.0 can be supported by Android 2.2 and higher
  • OpenGL ES 3.0 can be supported by Android 4.3 and higher
  • OpenGL ES 3.1 can be supported by Android 5.0 and above

basic introduction

Android can support OpenGL through the API or NDK provided by the framework. This article focuses on how to use OpenGL with the interface provided by the framework. For information about NDK, you can go to the official documentation to learn more.

There are two basic classes in the Android framework that allow you to create and manipulate graphics using the OpenGL ES API: GLSurfaceView and GLSurfaceView.Renderer. If your goal is to use OpenGL in an Android program, the first thing you need to do is to understand these two classes.

GLSurfaceView

This is a view class, you can use the OpenGL API to draw and manipulate graphics objects, which is very similar in function to SurfaceView. You can use this class by creating an instance of SurfaceView and adding your renderer. But if you want to capture touch screen events, you should extend GLSurfaceView to implement touch listeners. We will explain how to implement the touch monitor in a later article.

GLSurfaceView.Renderer

This interface defines the methods needed to draw graphics in GLSurfaceView. You must provide the implementation of this interface as a separate class and attach it to your GLSurfaceView instance using GLSurfaceView.setRenderer().
GLSurfaceView.Renderer requires the following methods to be implemented:

  • onSurfaceCreated(): When creating a GLSurfaceView, the system calls this method once. Use this method to perform operations that only need to be performed once, such as setting OpenGL environment parameters or initializing OpenGL graphics objects.
  • onDrawFrame(): The system calls this method every time GLSurfaceView is redrawn. Use this method as the main execution method for drawing (and redrawing) graphical objects.
  • onSurfaceChanged(): When the GLSurfaceView changes, the system calls this method. These changes include the size of the GLSurfaceView or the change of the device screen orientation. For example: when the device changes from portrait to landscape, the system calls this method. We should use this method to respond to changes in the GLSurfaceView container.

Guess you like

Origin blog.csdn.net/xfb1989/article/details/115334105