Android OpenGL ES View 构造

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:如果设备支持屏幕横向和纵向切换,这个方法将发生在横向 <-> 纵向互换时。此时可以重新设置绘制的纵横比率。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值