OpenGL ES中幾個重要函數

 

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是錯誤的

參數:
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不合法

名稱:
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點。
中心左面的座標值是負值,右面是正值。
移向屏幕頂端是正值,移向屏幕底端是負值。
移入屏幕深處是負值,移出屏幕則是正值。

)。
名稱
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
模板緩衝區

名稱
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函數




函數名:
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.



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)



Name
glClear – clear buffers to preset values
C Specification
void glClear(GLbitfield mask)



Name
glMatrixMode – specify which matrix is the current matrix
C Specification
void glMatrixMode(GLenum mode)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章