GLSurfaceView使用
OpenGL ES是是一个开源图形库,那么与之相关的需要一个东西去显示画面,在android里,opengl包里提供了一个View叫GLSurfaceView,它的定义如下:
An implementation of SurfaceView that uses the dedicated surface for
displaying OpenGL rendering.
它的特性如下:
Manages a surface, which is a special piece of memory that can be
composited into the Android view system.
Manages an EGL display, which enables OpenGL to render into a surface.
Accepts a user-provided Renderer object that does the actual rendering.
Renders on a dedicated thread to decouple rendering performance from the UI thread.
Supports both on-demand and continuous rendering.
Optionally wraps, traces, and/or error-checks the renderer's OpenGL calls.
可见系统已封装好一个View用于渲染画面并能进行相应设置。
使用步骤如下:
1.创建定义一个GLSurfaceView
2.调用GLSurfaceView的setEGLContextClientVersion设置版本号,可设为2
3.onResume 和 onPause分别调用GLSurfaceView相应的生命周期方法
4.调用GLSurfaceView的setRender设置自己实现GLSurfaceView.Render接口的类
5.Render接口有3个方法,分别是SurfaceCreated时候进行相应的初始化工作,SurfaceChange时候高宽的适配以及具体的DrawFrame方法
onSurfaceCreated(GL10 gl, EGLConfig config);
onSurfaceChan