OpenGL ES 2.0 Reference Pages
stackoverflow questions
OpenGL ES 1.1 Tutorial for Android
Buffer
- IO stream versus NIO blocks
Process data, IO stream, NIO blocks (packaged and transmitted) - Directbuffer allocate memory space from native, uncontrolled by Garbage collector.
- Buffer three state variables
- Capacity: How many memory allocate to buffer ;
- Position: Like pointer in the C / C++;
- Limit: control current area w/r, like [0, limit-1] beyond the area throw exception;
Name Conventions
- Constant "GL_" as prefix. such as GLES20.GL_COLOR_BUFFER_BIT
- Instruction "gl" as prefix. Such as gl.glClearColor() ; some instruction end with 3f or 4f, the 3, 4 represent of the number of parameters, "f" represent of parameter type float, Such as gl.glColor4f, (i,x represent of int,Such as gl.glColor4x)
- End with "v" OpenGL ES instruction, representing of Vector, Such as GLES20.glUniformMatrix4fv.
- boolean: GL_TRURE, GL_FALSE;
EGL
OpenGL ES的javax.microedition.khronos.opengles 包定义了平台无关的GL绘图指令,
EGL(javax.microedition.khronos.egl )则定义了控制displays ,contexts 以及surfaces 的统一的平台接口。
- Display(EGLDisplay) 是对实际显示设备的抽象。
- Surface(EGLSurface)是对用来存储图像的内存区域FrameBuffer的抽象,包括Color Buffer, Stencil Buffer ,Depth Buffer.
- Context (EGLContext) 存储OpenGL ES绘图的一些状态信息。
使用EGL的绘图的一般步骤:
- 获取EGLDisplay对象
- 初始化与EGLDisplay 之间的连接。
- 获取EGLConfig对象
- 创建EGLContext 实例
- 创建EGLSurface实例
- 连接EGLContext和EGLSurface.
- 使用GL指令绘制图形
- 断开并释放与EGLSurface关联的EGLContext对象
- 删除EGLSurface对象
- 删除EGLContext对象
- 终止与EGLDisplay之间的连接。
GLSurfaceView
- javax.microedition.khronos.opengles GL 绘图指令
- javax.microedition.khronos.egl EGL 管理Display, surface等
- android.opengl Android GL辅助类,连接OpenGL 与Android View,Activity
- javax.nio Buffer类
理论上不使用android.opengl 包中的类也可以开发Android上OpenGL ES应用,但此时就需要自己使用EGL来管理Display,Context, Surfaces 的创建,释放,捆绑
OpenGL ES 2 for Android -A Quick-Start Guide
- http://www.learnopengles.com/
- http://www.khronos.org/
- http://www.khronos.org/opengles/sdk/docs/reference_cards/OpenGL-ES-2_0-Reference-card.pdf
- http://www.khronos.org/opengles/sdk/docs/man/
- http://www.khronos.org/opengles/sdk/docs/manglsl/
- http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
- http://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.25.pdf
- http://www.khronos.org/registry/egl/
- https://pragprog.com/titles/kbogla/source_code
Getting started
Checking If the System Supports OpenGL ES 2.0
final ActivityManager activityManager =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final ConfigurationInfo configurationInfo =
activityManager.getDeviceConfigurationInfo();
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
Handling Android's Activity Life Cycle Events
@Override
protected void onPause() {
super.onPause();
// The following call pauses the rendering thread.
// If your OpenGL application is memory intensive,
// you should consider de-allocating objects that
// consume significant memory here.
mGLView.onPause();
}
@Override
protected void onResume() {
super.onResume();
// The following call resumes a paused rendering thread.
// If you de-allocated graphic objects for onPause()
// this is a good place to re-allocate them.
mGLView.onResume();
}
Using Static Imports
import static android.opengl.GLES20.*;
import static android.opengl.GLUtils.*;
import static android.opengl.Matrix.*;
Android studio Setting: Settings -> Code Style -> Java -> Imports
网友评论