opengles 2.0简介及相对1.1的变化

OpenGLES是一个让人崩溃的东西。在Andorid手机上做3D还就得用它。把我记的一些笔记分享在这里吧:

<strong><span style="color:#ff0000;">Android OpenGL ES简介 </span></strong>
Android系统使用OpenGL的标准接口来支持3D图形功能,android 3D图形系统也分为java框架和本地代码两部分。
本地代码主要实现的OpenGL接口的库,在Java框架层,javax.microedition.khronos.opengles是java标准的OpenGL包,
android.opengl包提供了OpenGL系统和Android GUI系统之间的联系。
Android的本地代码位于frameworks/base/opengl下,
JNI代码位于frameworks/base/core/com_google_android_gles_jni_GLImpl.cpp和frameworks/base/core/com_google_android_gles_jni_EGLImpl.cpp,
java类位于opengl/java/javax/microedition/khronos下
本地测试代码位于frameworks/base/opengl/tests。包括angeles、fillrate等14个测试代码,这些代码都可以通过终端进行本地调用测试(模拟器中使用adb shell)。
<strong><span style="color:#330033;">OpenGL ES 1.x
固定管线操作,支持glVertexPointer()等函数,不支持GLSL。头文件在ndk的GLES目录下,库文件是libGLESv1_CM.so。
OpenGL ES 2.x
可编程管线操作,不兼容1.x,不支持固定管线操作,例如glVertexPointer()等函数。支持GLSL(还必须用这个来编程)。头文件在ndk的GLES2目录下,库文件是libGLESv2.so。</span>

<span style="color:#ff0000;">OpenGL ES学习</span></strong> 
OpenGL定义了自己的数据类型。应该坚持使用这些OpenGL的数据类型,从而保证可移植性和效率。
OpenGL ES 目前不支持64位数据类型。
OpenGL ES 只支持三边形。
OpenGL ES 只支持gl开头的函数,glu库都不支持。
OpenGL ES 从 OpenGL中删除的功能:
1.  glBegin/glEnd
2.  glArrayElement
3.  显示列表
4.  求值器
5.  索引色模式
6.  自定义裁剪平面
7.  glRect
8.  图像处理(这个一般显卡也没有,FireGL/Quadro显卡有)
9.  反馈缓冲
10. 选择缓冲
11. 累积缓冲
12. 边界标志
13. glPolygonMode
14. GL_QUADS,GL_QUAD_STRIP,GL_POLYGON
15. glPushAttrib,glPopAttrib,glPushClientAttrib,glPopClientAttrib
16. TEXTURE_1D、TEXTURE_3D、TEXTURE_RECT、TEXTURE_CUBE_MAP
17. GL_COMBINE
18. 自动纹理坐标生成
19. 纹理边界
20. GL_CLAMP、GL_CLAMP_TO_BORDER
21. 消失纹理代表
22. 纹理LOD限定
23. 纹理偏好限定
24. 纹理自动压缩、解压缩
25. glDrawPixels,glPixelTransfer,glPixelZoom
26. glReadBuffer,glDrawBuffer,glCopyPixels


<strong><span style="color:#ff0000;">2.0和1.1不兼容。</span></strong>
- 2.0使用的头文件是ndk的include目录下的GLES2目录,有gl2.h,gl2ext.h,gl2platform.h,而1.1使用的是GLES目录。
- 2.0使用的库文件是ndk的lib目录下的libGLESv2.so,而1.1使用的是libGLESv1_CM.so。
- 2.0中取消了很多1.1函数,例如glMatrixModel和glLoadIdentity等。
OpenGL着色语言(GLSL――OpenGL Shading Language)
- 使用2.0,必须学此语言。因为很多1.1的函数都被取消了。
 
<div><dl style="margin: 0px; padding: 0px; border: 0px; list-style: none;"><dd style="margin: 0px; padding: 0px; border: 0px; list-style: none;"><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px;">区别有很多,慢慢总结下来:</p></dd><dd style="margin: 0px; padding: 0px; border: 0px; list-style: none;"><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px;">顶点属性</p></dd><dd style="margin: 0px; padding: 0px; border: 0px; list-style: none;"><p style="margin-top: 0px; margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px;">OpenGL ES中的顶点属性</p></dd></dl></div><div><dl style="margin: 0px; padding: 0px; border: 0px; list-style: none;"><dd style="margin: 0px; padding: 0px; border: 0px; list-style: none;"><table border="1" cellspacing="0" cellpadding="0" width="509" style="margin: 0px; padding: 0px; color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; background-color: rgb(164, 167, 146);"><tbody style="padding: 0px; margin: 0px;"><tr style="padding: 0px; margin: 0px;"><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p align="center" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"><span style="padding: 0px; margin: 0px;">Attribute</span></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p align="center" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"><span style="padding: 0px; margin: 0px;">OpenGL Enumerant</span></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p align="center" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"><span style="padding: 0px; margin: 0px;">OpenGL Function Call</span></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p align="center" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"><span style="padding: 0px; margin: 0px;">Dimensionality</span></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p align="center" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"><span style="padding: 0px; margin: 0px;">Types</span></p></td></tr><tr style="padding: 0px; margin: 0px;"><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">Position</p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">GL_VERTEX_ARRAY</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glVertexPointer</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">2, 3, 4</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">byte, short, fixed, float</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td></tr><tr style="padding: 0px; margin: 0px;"><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">Normal</p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">GL_NORMAL_ARRAY</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glNormalPointer</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">3</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">byte, short, fixed, float</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td></tr><tr style="padding: 0px; margin: 0px;"><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">Color</p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">GL_COLOR_ARRAY</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glColorPointer</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">4</p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">ubyte, fixed, float</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td></tr><tr style="padding: 0px; margin: 0px;"><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">Point Size</p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">GL_POINT_SIZE_ARRAY_OES</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glPointSizePointerOES</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">1</p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">fixed, float</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td></tr><tr style="padding: 0px; margin: 0px;"><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">Texture Coordinate</p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">GL_TEXTURE_COORD_ARRAY</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glTexCoordPointer</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">2,3,4</p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">byte, short, fixed, float</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td></tr><tr style="padding: 0px; margin: 0px;"><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">Generic Attribute(ES 2.0)</p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">N/A</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glVertexAttribPointer</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">1,2,3,4</p></td><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">byte, ubyte, short, ushort, fixed, float</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p></td></tr></tbody></table><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; background-color: rgb(164, 167, 146);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; background-color: rgb(164, 167, 146);">OpenGL ES 2.0只有最后一行,它需要你自定义属性。回忆一下HelloArrow中不同rendering engines开启属性的方法:</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; background-color: rgb(164, 167, 146);"> <wbr></wbr></p><table border="1" cellspacing="0" cellpadding="0" style="margin: 0px; padding: 0px; color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; background-color: rgb(164, 167, 146);"><tbody style="padding: 0px; margin: 0px;"><tr style="padding: 0px; margin: 0px;"><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">//ES 1.1</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glEnableClientState(GL_VERTEX_ARRAY);</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glEnableClientState(GL_COLOR_ARRAY);</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">//ES 2.0</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glEnableVertexAttribArra<wbr>y(positionSlot);</wbr></p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glEnableVertexAttribArra<wbr>y(colorSlot);</wbr></p></td></tr></tbody></table><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; background-color: rgb(164, 167, 146);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; background-color: rgb(164, 167, 146);">在ES 1.1中,是用内置常量来开启顶点属性的,而ES 2.0中则是用从shader中导出的常量来开始(positionSlot与colorSlot)。接着向OpenGL指明要开启顶点属性的类型与维度:</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; background-color: rgb(164, 167, 146);"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; line-height: 21px; color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; background-color: rgb(164, 167, 146);"> <wbr></wbr></p><table border="1" cellspacing="0" cellpadding="0" style="margin: 0px; padding: 0px; color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; background-color: rgb(164, 167, 146);"><tbody style="padding: 0px; margin: 0px;"><tr style="padding: 0px; margin: 0px;"><td valign="top" style="margin: 0px; padding: 0px; font-family: Verdana, 宋体, sans-serif; line-height: 18px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">// OpenGL ES 1.1</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glVertexPointer(2, GL_FLOAT, ... );</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glColorPointer(4, GL_FLOAT, ... );</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;"> <wbr></wbr></p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">// OpenGL ES 2.0</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glVertexAttribPointer(positionSlot, 2, GL_FLOAT, ...);</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal;">glVertexAttribPointer(colorSlot, 4, GL_FLOAT, ...);</p></td></tr></tbody></table>
<span style="color: rgb(73, 73, 73); font-family: simsun; font-size: 14px; line-height: 21px; background-color: rgb(164, 167, 146);"></span></dd></dl></div>

san-angeles NDK OpenGL ES 1.1的例子程序 2012-3-8
San Angeles,查维基百科,是一个虚构的未来概念城市,位于南加州。常在电影中出现,来源自Los Angeles和San Diego.
该程序的演示效果是,观察一个宏伟的城市,地面是镜面有建筑倒影,城市中有飞船飞过。前后有5、6个观察点,而且镜头在每个观察点不停的移动。
这个例子,用NDK(C++)调用OpenGL ES 1.1来绘制了San Angeles这个城市。基本上全部使用了NDK,Java程序只有1个。
用vc2005演示一下,目的通过跟踪代码了解一些细节。方法是:
- 将jni下所有的.h文件,以及demo.c,app-win32.c复制出来,放在一个专门的目录下,然后改造成用OpenGL的而不是ES的。(或者干脆删除大段的绘制代码,保证编译通过)
首先分析Java代码
- DemoActivity.java,这是唯一的Java文件,它主要需要下列4个jni的接口:
- private static native void nativeInit(); // 初始化
- private static native void nativeResize(int w, int h);
- private static native void nativeRender(); // 绘制1帧
- private static native void nativeDone();
其次分析C++代码 app-android.c
- 首先,调用了importGLInit(),动态导入OpenGL的库。
- 其次,调用了 appInit(),在内存中建立了平台无关的3D对象集合。建立方法是用一个数组,用类似画圆拔高的方式产生诸多三角形。
- 然后,在每个时钟周期中调用appRender(),细节是:
- prepareFrame(width, height); // 准备OpenGL ES绘制框架。其实就是清空颜色和深度缓冲,重置投影和模型矩阵。
- camTrack(); // 算好在当前时钟周期,镜头的位置、朝向及焦距等。然后调用gluLookAt来实现。
- configureLightAndMaterial(); // 设置光源和材质
- drawModels(-1); // 先绘制倒影(其实就是将所有模型z轴倒过来画)
- 第一个循环,是画精致的物体
- 第二个循环,是画运动的物体
- drawGroundPlane(); // 再绘制镜子一般的地面。在绘制前取消光照,打开混合,然后绘制。绘制后还原状态。
- drawModels(1); // 再绘制所有模型
- drawFadeQuad(); // 最后绘制淡出框,用融合的方式画一个遮住整个视口的2D框,融合系数和时间相关。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值