//如果是OpenGLES 1.1, getGLVersion() == 0x00010001
//如果是OpenGLES 2.0, getGLVersion() == 0x00020000
public int getGLVersion()
{
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
return info.reqGlEsVersion;
}
http://www.glprogramming.com/red/
http://alien.dowling.edu/~vassil/thebluebook/
http://blog.youkuaiyun.com/vagrxie/archive/2009/11/06/4776410.aspx
// OpenGL 函数命名
一般的命名方式都是 xxxx[n][t] C 语言没有函数重载机
glVertex2f (-0.5, -0.5); glVertex3f (-0.5, 0.5, 0.0); glVertex*
xxxx 表示函数的意义
[t] 用于表示此函数对应的类型
[n]参数的个数
s ----------表示 16 位整数
i 表示 32 位整数
d 表示 64 位浮点数
f 表示 32 位浮点数
//离我们近的物体绘制在后面,覆盖掉远的物体。
GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do
//作用是清除颜色缓冲区
//假如没有这样的操作,以前留在显存 / 内存 ( 不确定 ) 中的值会影响我们的操作
glClear ( GL_COLOR_BUFFER_BIT );
//glBegin 与 glEnd 很明显是一对
//标志着一组 OpenGL 操作的开始和结束。
//并且在参数中告诉了 OpenGL 下面的操作是针对什么图形进行的,
//此例中 GL_QUADS 是表示四边形。
glBegin ( GL_QUADS ) 与 glEnd
//顶点的代码
glVertex3f (-0.5, -0.5, 0.0);
// 强制执行已经指定的 OpenGL 命令
glFlush
//改变点的大小 GL_POINTS 默认大小为 1 个像素
glPointSize
//改变直线的宽度 GL_LINES 默认大小为 1 个像素
glLineWidth (5);
//多边形
GL_TRIANGLES 绘制三角形 GL_QUADS 表示四边形 GL_POLYGON 表示多边形(必须是凸的)
// glClearColor 就不能放在 glBegin,glEnd 中, glColor* 就行。
//函数改变背景颜色 The default values are all zero.
glClearColor ( GLclampf red , GLclampf green , GLclampf blue , GLclampf alpha )
//指定前景
glColor * glColor4f (1.0, 1.0, 1.0, 1.0);
//着色模型 参数可以是 GL_SMOOTH 和 GL_FLAT
GL11.glShadeModel(GL11.GL_SMOOTH)
GL_FLAT 时,表示单一着色 整个图元都是一个颜色
GL_SMOOTH 时,表示平滑着色 这个时候在指定顶点的时候用了不同的颜色会出现渐变效
OpenGL 模式的着色模型就是平滑的。
//坐标体系
gluOrtho2D 函数的作用就是,指定整个 2D 平面的左,右,下,上的坐标,
以指定整个坐标体系
gluOrtho2D (0.0, (double )WIDTH , (double )HEIGHT , 0.0);
指定客户区左边界坐标为 0 ,右边界坐标为客户区宽度,下边界坐标为客户区高度,
上边界为 0 ,这样,一个 Windows 坐标体系就诞生了
//OpenGL 支持移动坐标系的函数是 glTranslate* ,
//只有 glTranslatef,glTranslated
void glTranslated( GLdouble x, GLdouble y, GLdouble z );
void glTranslatef( GLfloat x, GLfloat y, GLfloat z );
//旋转
glRotate*
void glRotated( GLdouble angle, GLdouble x, GLdouble y, GLdouble z );
void glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z );
angle 来指定旋转的角度
围绕着 Z 轴旋转 z 参数设为了 1.0
//顶点数组
//启用顶点数组
glEnableClientState(GL_VERTEX_ARRAY);
//指定顶点数组的数据
glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer);
glVertexPointer(2, GL_FLOAT, 0, fVertices);
size: 数据以2个位一组
type:数据类型
stride:,跨度默认为0表示数据紧密排列,指针自然指向刚才分配的顶点数组数据
// 顶点数组数据定义例子
GLfloat fVertices[] = { -0.5, -0.5,0.5, -0.5, 0.5, 0.5,-0.5, 0.5};
// render a vertex using the specified vertex array element
glArrayElement( GLint i);
//顶点指定函数:glDrawElemets 事实上,在OpenGL中命名中带Draw的一般都不需要glBegin和glEnd
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, byRectIndices);
GLubyte byRectIndices[] = { 0, 1, 2, 3};
glBegin(mode)
for
( i = 0; i < count; i++)
glArrayElement(indices[i]);
glEnd();
glDrawElements( GLenum mode,
GLsizei count,
GLenum type,
const GLvoid * indices);
//可以一个顶两->N个glDrawElemetns
glMultiDrawElements( GLenum mode,
const GLsizei * count,
GLenum type,
const GLvoid ** indices,
GLsizei primcount);
//照相机比喻
1.确定照相机的位置的过程对应于“视图变换”(Viewing Transformations)
2.确定物体位置的过程对应于“模型变换”(Modeling Transformations)
3.确定照相机放大倍数的过程对应于“投影变换”(Projection Transformations)
4.确定照片大小的过程对应于“视口变换”(Viewport Transformations)
//确定视角
gluLookAt( GLdouble eyeX,
GLdouble eyeY,
GLdouble eyeZ,
GLdouble centerX,
GLdouble centerY,
GLdouble centerZ,
GLdouble upX,
GLdouble upY,
GLdouble upZ);
从哪里(Where look from,前三个参数),看哪去(where look at,中间三个参数),
怎么看(how to look at,最后三个参数)
eyeX, eyeY, eyeZ
Specifies the position of the eye point.
centerX, centerY, centerZ
Specifies the position of the reference point.
upX, upY, upZ
Specifies the direction of the up vector.
//正投影:将三维空间的事物设想投影在二维空间中,然后画下来
//投影变换的过程就像是照相机选镜头的过程,目的是确定视野
glOrtho来指定一个正交平行的矩形,屏幕上显示的就是此物体在此矩形的正面的投影
glOrtho( GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble nearVal,
GLdouble farVal);
Parameters
left, right
Specify the coordinates for the left and right vertical clipping planes.
bottom, top
Specify the coordinates for the bottom and top horizontal clipping planes.
nearVal, farVal
Specify the distances to the nearer and farther depth clipping planes.
These values are negative if the plane is to be behind the viewer.
//用于指定以下的变换是针对投影变换的
glMatrixMode(GL_PROJECTION);
用于指定,针对模型变换。
glMatrixMode(GL_MODELVIEW);
方式调用时,(默认值)表示针对模型变换。
//透视投影 越远的越小,越近的越大,并且所有物体最终会消失在远方(地平线)
glFrustum指定的方式与glOrtho很像,参数意义也一致,仅仅是使用后OpenGL使用的投影方式不同,
gluPerspective函数指定的方式是模拟观察者(照相机)的视角,用fovy指定观察者的上下视角(及在y-z平面上观察的角度)
,aspect指定观察宽度与高度的比,
然后用zNear指定离观察者较近的截面,用zFar指定离观察者较远的截面(都指离观察者的距离),
gluPerspective — set up a perspective projection matrix
C Specification
void gluPerspective( GLdouble fovy,
GLdouble aspect,
GLdouble zNear,
GLdouble zFar);
//视口变换 确认照片大小,在实际中,确认的是绘制的区域
glViewport — set the viewport
C Specification
void glViewport( GLint x,
GLint y,
GLsizei width,
GLsizei height);
Parameters
x, y
Specify the lower left corner of the viewport rectangle,
in pixels. The initial value is (0,0).
width, height
Specify the width and height
of the viewport.
When a GL context is first attached to a window,
width and height are set to the dimensions of that
window.