opengl es 2.0 java_OpenGl-ES2.0 For Android 读书笔记(一)

一、开始

OpenGl主要需要实现两个类:

**GLSurfaceView

**

This class is a View where you can draw and manipulate objects using OpenGL API calls and is similar in function to a SurfaceView. You can use this class by creating an instance of GLSurfaceView and adding your Renderer to it. However, if you want to capture touch screen events, you should extend the GLSurfaceView class to implement the touch listeners, as shown in OpenGL training lesson, Responding to Touch Events.

这个是Android官方的解释,跟SurfaceView类似的可以用OpenGL去绘制的View。

**GLSurfaceView.Renderer

**

This interface defines the methods required for drawing graphics in a GLSurfaceView. You must provide an implementation of this interface as a separate class and attach it to your GLSurfaceView instance using GLSurfaceView.setRenderer().

GLSurfaceView需要设置一个GLSurfaceView.Renderer的实现类去做OpenGl绘制的处理。主要有三个方法:

[onSurfaceCreated()](https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html#onSurfaceCreated(javax.microedition.khronos.opengles.GL10, javax.microedition.khronos.egl.EGLConfig)): The system calls this method once, when creating the GLSurfaceView. Use this method to perform actions that need to happen only once, such as setting OpenGL environment parameters or initializing OpenGL graphic objects.

[onSurfaceChanged()](https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html#onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)): The system calls this method when the GLSurfaceView geometry changes, including changes in size of the GLSurfaceView or orientation of the device screen. For example, the system calls this method when the device changes from portrait to landscape orientation. Use this method to respond to changes in the GLSurfaceView container.

onDrawFrame(): The system calls this method on each redraw of the GLSurfaceView. Use this method as the primary execution point for drawing (and re-drawing) graphic objects.

从方法名字就可以看出来

onSurfaceCreated()主要做一些初始化的操作

onSurfaceChanged()主要做一些在view改变时候的处理

onDrawFrame()主要做绘制处理

二、绘制简单的撞球图面

1.总览

我们最终完成的效果如下图:

80635e503436

效果图.png

首先我们思考下我们怎么去画图,我们需要一只笔,需要知道在怎么地方画什么,所以我们的使用OpenGL去绘制的大概步骤如下:

定义绘图数据

告诉手机如何使用这些数据去绘制

2.定义绘图数据

首先我们需要知道一

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值