Android OpenGL ES View 构造
* 注:参考 http://wiki.jikexueyuan.com/project/opengl-es-basics/opengl-es-view.html
在开始使用Android OpenGL 时,需要知道两样东西
GLSurfaceView
- 起到连接 OpenGL ES与Android 的 View 层次结构之间的桥梁作用。
GLSurfaceView.Renderer
- 统一图形绘制
编写 OpenGL ES 应用的起始点是从类 GLSurfaceView 开始,设置 GLSurfaceView 只需调用一个方法来设置 OpenGLView 用到的 GLSurfaceView.Renderer.
public void setRenderer(GLSurfaceView.Renderer renderer)
GLSurfaceView.Renderer 定义了一个统一图形绘制的接口,它定义了如下三个接口函数:
//Called when the surface is created or recreated.
public void onSurfaceCreated(GL10 gl, EGLConfig config)
//Called to draw the current frame.
public void onDrawFrame(GL10 gl)
//Called when the surface changed size.
public void onSurfaceChanged(GL10 gl, int width, int height)
- onSurfaceCreated:在这个方法中主要用来设置一些绘制时不常变化的参数,比如:背景色,是否打开 z-buffer 等。
- onDrawFrame:定义实际的绘图操作。
- onSurfaceChanged:如果设备支持屏幕横向和纵向切换,这个方法将发生在横向 <-> 纵向互换时。此时可以重新设置绘制的纵横比率。