Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5513863
  • 博文数量: 763
  • 博客积分: 12108
  • 博客等级: 上将
  • 技术积分: 15717
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-28 21:21
个人简介

业精于勤,荒于嬉

文章分类

全部博文(763)

文章存档

2018年(6)

2017年(15)

2016年(2)

2015年(31)

2014年(14)

2013年(87)

2012年(75)

2011年(94)

2010年(190)

2009年(38)

2008年(183)

2007年(28)

分类: C/C++

2010-02-02 18:38:15

glVertexPointer

void glVertexPointer(GLint size,
GLenum type,
GLsizei stride,
const GLvoid * pointer)

Parameters
size Specifies the number of coordinates per vertex. Must be 2, 3, or 4. The
initial value is 4.
type Specifies the data type of each vertex coordinate in the array. Symbolic
constants GL_BYTE, GL_SHORT, and GL_FIXED, are accepted. However, the
initial value is GL FLOAT.
The common profile accepts the symbolic constant GL FLOAT as well.
stride Specifies the byte offset between consecutive vertices. If stride is 0, the
vertices are understood to be tightly packed in the array. The initial value
is 0.
pointer Specifies a pointer to the first coordinate of the first vertex in the array.
The initial value is 0.


参数:
size:指定了每个顶点对应的坐标个数,只能是2,3,4中的一个,默认值是4
type:指定了数组中每个顶点坐标的数据类型,可取常量:GL_BYTE, GL_SHORT,GL_FIXED,GL_FLOAT;
stride:指定了连续顶点间的字节排列方式,如果为0,数组中的顶点就会被认为是按照紧凑方式排列的,默认值为0
pointer:制订了数组中第一个顶点的首地址,默认值为0,对于我们的android,大家可以不用去管什么地址的,一般给一个IntBuffer就可以了。


Description
glVertexPointer specifies the location and data of an array of vertex coordinates
to use when rendering. size specifies the number of coordinates per vertex and type
the data type of the coordinates. stride specifies the byte stride from one vertex to
the next allowing vertices and attributes to be packed into a single array or stored
in separate arrays. (Single-array storage may be more efficient on some implementations.)
When a vertex array is specified, size, type, stride, and pointer are saved as
client-side state.
If the vertex array is enabled, it is used when glDrawArrays, or glDrawElements
is called. To enable and disable the vertex array, call glEnableClientState
and glDisableClientState with the argument GL VERTEX ARRAY. The vertex array
is initially disabled and isn’t accessed when glDrawArrays or glDrawElements is
called.
Use glDrawArrays to construct a sequence of primitives (all of the same type)
from prespecified vertex and vertex attribute arrays. Use glDrawElements to construct
a sequence of primitives by indexing vertices and vertex attributes.

If the vertex array is enabled, it is used when glDrawArrays, or glDrawElements
is called. To enable and disable the vertex array, call glEnableClientState
and glDisableClientState with the argument GL_VERTEX ARRAY. The vertex array
is initially disabled and isn’t accessed when glDrawArrays or glDrawElements is
called.
Use glDrawArrays to construct a sequence of primitives (all of the same type)
from prespecified vertex and vertex attribute arrays. Use glDrawElements to construct
a sequence of primitives by indexing vertices and vertex attributes


描述:
当开始render的时候,glVertexPointer 用一个数组指定了每个顶点的坐标,
size指定了每个顶点的坐标个数
type指定了每个坐标的数据类型,(和尚注:注意,这里不同的数据类型含义不同,如果选择GL_FIXED,那么0x10000表示单位长度,如果选择GL_FLOAT那么1.0f表示单位度。)

stride指定了一个顶点和下一个顶点间数据的排列方式,是"单一数组"还是"分散数组",单一数组的存储方式通常是更具效率的。当一个顶点数组被指定以后,size,type,stride,pointer被存储成client-side.
当glDrawArrays或者glDrawElements被调用的时候,如果顶点数组处于可用状态,就会被使用;可以使用glEnableClientState或者glDisableClientState来激活或者禁用一个顶点数组,顶点数组默认是不可用并且是不可被glDrawArrays、glDrawElements两个函数使用的。

使用glDrawArrays函数可以根据顶点数组构建一个原始构图序列
使用glDrawElements可以根据序列化的顶点集合来创建相同的序列



Notes
glVertexPointer is typically implemented on the client side

Errors
GL_INVALID_VALUE is generated if size is not 2, 3, or 4.
GL_INVALID_ENUM is generated if type is is not an accepted value.
GL_INVALID_VALUE is generated if stride is negative.

错误:
GL_INVALID_VALUE  size 不是 2, 3, 4中的一个的时候
GL_INVALID_ENUM   type 不是一个允许的值.
GL_INVALID_VALUE  stride是错误的









函数名:
glDrawArrays – 从数组提供原始数据
void glDrawArrays(GLenum mode, GLint first, GLsizei count)

Parameters
mode Specifies what kind of primitives to render. Symbolic constants GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP,GL_TRIANGLE_FAN, and GL_TRIANGLES are accepted.
first Specifies the starting index in the enabled arrays.
count Specifies the number of indices to be rendered.

参数:
mode  指定要提供的原始图形的样式,比如:GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP,GL_TRIANGLE_FAN, GL_TRIANGLES
first 指定了被激活的数组的索引起始点,通常为0
count 取几个数,和first配合使用


Description
glDrawArrays specifies multiple geometric primitives with very few subroutine calls.
You can prespecify separate arrays of vertices, normals, colors, and texture coordinates
and use them to construct a sequence of primitives with a single call to glDrawArrays.
When glDrawArrays is called, it uses  sequential elements from each enabled
array to construct a sequence of geometric primitives, beginning with element
first. mode specifies what kind of primitives are constructed, and how the array elements
construct those primitives. If GL_VERTEX_ARRAY is not enabled, no geometric
primitives are generated.
Vertex attributes that are modified by glDrawArrays have an unspecified value
after glDrawArrays returns. For example, if GL_COLOR_ARRAY is enabled, the value of
the current color is undefined after glDrawArrays executes. Attributes that aren’t
modified remain well defined.




描述:
glDrawArrays 提供了多种基本几何样式的绘制,你可以对各种数组,比如说顶点、颜色、材质的坐标进行分割(和尚注:通过first和count参数),并且使用这些分割出来的坐标来构造一个显示队列。

当glDrawArrays 被调用的时候,它会从first参数开始,按照mode指定的样式,按照顺序使用被激活的数组中的每个元素去构造一个由基本几何单元构成的队列,如果GL_VERTEX_ARRAY没有处于激活状态,不会有任何几何单元被创建。
在glDrawArrays 被返回后,被这个函数编辑的顶点的属性将成为一个不确定的值,例如:glDrawArrays 函数被调用以后,当前颜色将会变成一个未定义的值。没有被函数引用的顶点属性会保留与原本的属性。(和尚注:很绕口,关于这一小段的翻译,我反复修改了很多遍,意思其实很简单,如果一个顶点数组被glDrawArrays使用,那么使用后这些顶点决定的那个几何图形的属性,比如颜色,就会丢失,不会影响到下一个glDrawArrays 的绘制,因此当你要重新用glDrawArrays 绘制一个顶点集合的话,就要重新用glColor4f来设定颜色)

Errors
GL_INVALID_ENUM is generated if mode is not an accepted value.
GL_INVALID_VALUE is generated if count is negative.



错误:
GL_INVALID_ENUM  mode不是一个被允许的值
GL_INVALID_VALUE  count不合法












Name
glTranslatef, glTranslatex – multiply the current matrix by a translation matrix
C Specification
void glTranslatef(GLfloat x, GLfloat y, GLfloat z)
void glTranslatex(GLfixed x, GLfixed y, GLfixed z)

名称:
glTranslatef, glTranslatex  在一个副本(和尚:不知道翻译成副本合适不合适)模型上确定一个基于某个增量的新原点(和尚注:自己明白,要想写出合适的译文真的好难  )
void glTranslatef(GLfloat x, GLfloat y, GLfloat z)
void glTranslatex(GLfixed x, GLfixed y, GLfixed z)


Parameters
x, y, z Specify the x, y, and z coordinates of a translation vector.


参数:
x,y,z指定了一个基于某个方向的x,y,z坐标



Description
glTranslate produces a translation by (x, y, z). The current matrix (see glMatrixMode)
is multiplied by this translation matrix, with the product replacing the
current matrix, as if glMultMatrix were called with the following matrix for its
argument:
1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1
If the matrix mode is either GL_MODELVIEW or GL_PROJECTION, all objects drawn after
a call to glTranslate are translated.
Use glPushMatrix and glPopMatrix to save and restore the untranslated coordinate
system.
描述:
glTranslate 根据x,y,z生成了一个副本模型,当前模型是一个基于此模型的增量模型,glMultMatrix 被调用的时候用以下模型来做参数:

1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1
如果模型模式是either GL_MODELVIEW 或者 GL_PROJECTION,所有的对象都会在glTranslate 被调用以后绘制


使用glPushMatrix 和 glPopMatrix来保存和恢复未被副本化的坐标系统

(和尚注:每一个层都是基于自己的坐标系统的,关于x,y,z的含义,参看以下说明:
OpenGL屏幕中心的坐标值是X和Y轴上的0.0f点。
中心左面的坐标值是负值,右面是正值。
移向屏幕顶端是正值,移向屏幕底端是负值。
移入屏幕深处是负值,移出屏幕则是正值。

)。



Name
glClear – clear buffers to preset values
C Specification
void glClear(GLbitfield mask)
名称
glClear – 为重设数据清空缓冲区
void glClear(GLbitfield mask)
Parameters
mask Bitwise OR of masks that indicate the buffers to be cleared.
Valid masks are GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, and GL_STENCIL_BUFFER_BIT.


参数:
掩码: 用OR连接起来的掩码,这些掩码决定了哪些缓冲区将被清除,可用的掩码有:
GL_COLOR_BUFFER_BIT
GL_DEPTH_BUFFER_BIT
GL_STENCIL_BUFFER_BIT


Description
glClear sets the bitplane area of the window to values previously selected by gl-
ClearColor, glClearDepth, and glClearStencil.
The pixel ownership test, the scissor test, dithering, and the color buffer masks
affect the operation of glClear. The scissor box bounds the cleared region. Alpha
function, blend function, logical operation, stenciling, texture mapping, and depthbuffering
are ignored by glClear.
glClear takes a single argument that is the bitwise OR of several values indicating
which buffer is to be cleared.
The values are as follows:
GL COLOR BUFFER BIT
Indicates the color buffer.
GL DEPTH BUFFER BIT
Indicates the depth buffer.
GL STENCIL BUFFER BIT
Indicates the stencil buffer.
The value to which each buffer is cleared depends on the setting of the clear value
for that buffer.


描述:
glClear把窗口的bitplane区域的值设置成您设置的ClearColor, glClearDepth, glClearStencil
ownership测试、切图测试、抖动、颜色缓冲掩码受glClear的影响(空白区域的盒子跳动)Alpha通道函数,混合函数,逻辑操作,模板操作,纹理材质操作,深度缓冲区操作将被glClear忽略。

glClear的参数用几个OR连接3个可选项来制定要清楚哪些缓冲区
关于可选项的说明:
GL COLOR BUFFER BIT
颜色缓冲区
GL DEPTH BUFFER BIT
深度缓冲区
GL STENCIL BUFFER BIT
模板缓冲区




Name
glMatrixMode – specify which matrix is the current matrix
C Specification
void glMatrixMode(GLenum mode)
名称
glMatrixMode – 选择当前模型

Parameters
mode Specifies which matrix stack is the target for subsequent matrix operations.
Three values are accepted: GL_MODELVIEW, GL_PROJECTION, and
GL_TEXTURE. The initial value is GL_MODELVIEW.

参数:
mode 指定随后的模型操作的目标是哪一个模型堆栈,可选以下三个值
GL_MODELVIEW
GL_PROJECTION
GL_TEXTURE
默认值是 GL_MODELVIEW


Description
glMatrixMode sets the current matrix mode. mode can assume one of four values:
GL MODELVIEW
Applies subsequent matrix operations to the modelview matrix stack.
GL PROJECTION
Applies subsequent matrix operations to the projection matrix stack.
GL TEXTURE
Applies subsequent matrix operations to the texture matrix stack.


描述:
glMatrixMode 函数设定当前的模型模式,mode可以选择三个中的一个:
GL_MODELVIEW
把随后的模型操作应用到modelview的模型堆栈上
GL_PROJECTION
把随后的模型操作应用到projection 的模型堆栈上
GL_TEXTURE
把随后的模型操作应用到texture 的模型堆栈上



Errors
GL_INVALID_ENUM is generated if mode is not an accepted value.
错误:
GL_INVALID_ENUM mode选择了一个错误的值

See Also
glLoadMatrix, glPushMatrix
参看:
glLoadMatrix, glPushMatrix函数




附带做了几个小例子,有详细的说明,希望对初学者有一点点帮助!

未完待续...

阅读(2487) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~