https://developer.android.com/training/building-graphics.html

https://developer.android.com/training/graphics/opengl/index.html

The Android framework provides plenty of standard tools for creating attractive, functional graphical user interfaces. However, if you want more control of what your application draws on screen, or are venturing into three dimensional graphics, you need to use a different tool. The OpenGL ES APIs provided by the Android framework offers a set of tools for displaying high-end, animated graphics that are limited only by your imagination and can also benefit from the acceleration of graphics processing units (GPUs) provided on many Android devices.

Android框架提供了大量的标准工具来创建具有吸引力的、功能强大的图形用户界面。然而,如果你想要更多的控制你的应用程序在屏幕上的吸引,或者是冒险进入三维图形,你需要使用不同的工具。Android框架提供的OpenGL ES api提供了一套用于显示高端、动画图形的工具,这些工具仅受您的想象力的限制,而且还可以从许多Android设备上提供的图形处理单元(gpu)的加速中获益。(这块不好翻译,以上来自有道翻译,凑合看)

Platform Architecture

从图中可以看出Openg ES属于Native库。

Note: Be careful not to mix OpenGL ES 1.x API calls with OpenGL ES 2.0 methods! The two APIs are not interchangeable and trying to use them together only results in frustration and sadness.

interchangeable adj. 可互换的;可交换的;可交替的

一定不要将OpenGL ES 1.x 和OpenGL ES 2.0 的方法混合使用,要不然结果会令你失望。

A GLSurfaceView is a specialized view where you can draw OpenGL ES graphics. It does not do much by itself. The actual drawing of objects is controlled in the GLSurfaceView.Renderer that you set on this view. In fact, the code for this object is so thin, you may be tempted to skip extending it and just create an unmodified GLSurfaceView instance, but don’t do that. You need to extend this class in order to capture touch events, which is covered in the Responding to Touch Events lesson.

specialized adj. 专业的;专门的
GLSurfaceView是一个可以在上面绘制 OpenGL ES 的View,它本身的工作并不多,真正的绘制工作是由GLSurfaceView.Renderer来做,它的代码很少,你甚至想要跳过实现它自己写一个原封不动的类,但是最好不要这样做,你需要实现它来处理touch事件。

class MyGLSurfaceView extends GLSurfaceView {

    private final MyGLRenderer mRenderer;

    public MyGLSurfaceView(Context context){
        super(context);

        // Create an OpenGL ES 2.0 context
        setEGLContextClientVersion(2);

        mRenderer = new MyGLRenderer();

        // Set the Renderer for drawing on the GLSurfaceView
        setRenderer(mRenderer);
    }
}

The implementation of the GLSurfaceView.Renderer class, or renderer, within an application that uses OpenGL ES is where things start to get interesting. This class controls what gets drawn on the GLSurfaceView with which it is associated. There are three methods in a renderer that are called by the Android system in order to figure out what and how to draw on a GLSurfaceView:

  • onSurfaceCreated() - Called once to set up the view’s OpenGL ES environment
  • onDrawFrame() - Called for each redraw of the view.
  • onSurfaceChanged() - Called if the geometry of the view changes, for example when the device’s screen orientation changes.

实现GLSurfaceView.Renderer用来控制在GLSurfaceView上绘制,需要实现以上三个方法。

public class MyGLRenderer implements GLSurfaceView.Renderer {

    public void onSurfaceCreated(GL10 unused, EGLConfig config) {
        // Set the background frame color
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    }

    public void onDrawFrame(GL10 unused) {
        // Redraw background color
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    }

    public void onSurfaceChanged(GL10 unused, int width, int height) {
        GLES20.glViewport(0, 0, width, height);
    }
}

masterpiece n. 杰作;绝无仅有的人
can be a little tricky 可能有点棘手
coordinates n. [数] 坐标;相配之衣物
projection n. 投射;规划;突出;发射;推测
simulation n. 仿真;模拟;模仿;假装
Motion n. 动作;移动;手势;请求;意向

OpenGLES官方demo下载链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值