之前介紹了什么是 OpenGL ES ,OpenGL ES 管道的概念,什么是 EGL,Android中OpenGL ES 的開發包以及 GLSurfaceView,OpenGL ES 所支持的基本幾何圖形:點,線,面,已及如何使用這些基本幾何通過構成較復雜的圖像(20面體)。
但到目前為止還只是繪制 2D 圖形,而忽略了一些重要的概念,3D 坐標系,和 3D 坐標變換,在介紹 OpenGL ES Demo 程序框架時,創建一個 OpenGLRenderer 實現 GLSurfaceView.Renderer 接口
public void onSurfaceChanged(GL10 gl, int width, int height) {
// Sets the current view port to the new size.
gl.glViewport(0, 0, width, height);
// Select the projection matrix
gl.glMatrixMode(GL10.GL_PROJECTION);
// Reset the projection matrix
gl.glLoadIdentity();
// Calculate the aspect ratio of the window
GLU.gluPerspective(gl, 45.0f,
(float) width / (float) height,
0.1f, 100.0f);
// Select the modelview matrix
gl.glMatrixMode(GL10.GL_MODELVIEW);
// Reset the modelview matrix
gl.glLoadIdentity();
}
}
我們忽略了對 glViewport,glMatrixMode,gluPerspective 以及 20 面體時 glLoadIdentity,glTranslatef,glRotatef 等方法的介紹,這些都涉及到如何來為 3D 圖形構建模型,在下面的幾篇將詳細介紹 OpenGL ES 的坐標系和坐標變換已經如何進行3D建模。