Android OpenGLES 示例 May 23, 2012 • Shingwa Six 在android中使用opengles进行开发,主要需要三步. 1.新建一个继承自GLSurfaceView的视图,重写构造函数和onTouchEvent方法. public class VortexView extends GLSurfaceView { private VortexRenderer _renderer; public VortexView(Context context) { super(context); _renderer = new VortexRenderer(); setRenderer(_renderer); } //该方法用于响应触摸事件 public boolean onTouchEvent(final MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { } if (event.getAction() == MotionEvent.ACTION_MOVE) { } return true; } } 2.新建一个继承自GLSurfaceView.Rederer的渲染器,重写onSurfaceCreated,onSurfaceChanged,onDrawFrame public class VortexRenderer implements GLSurfaceView.Renderer { //渲染器创建时执行,用于初始化. public void onSurfaceCreated(GL10 gl, EGLConfig config) { } //屏幕大小改变时执行 public void onSurfaceChanged(GL10 gl, int width, int height) { } //渲染帧时执行 public void onDrawFrame(GL10 gl) { } } 3.将GLSurfaceView的实例添加到活动对象上. public class test extends Activity { private VortexView _vortexView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); _vortexView = new VortexView(this); setContentView(_vortexView); } } 4.最终运行效果图 5.demo工程下载 android_opengles_demo.zip 《Android OpenGLES 示例》 由 Shingwa Six 创作,采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。 Please enable JavaScript to view the comments powered by Disqus.