Game Development Reference
In-Depth Information
The parameters of the function glVertexAttribPointer() are explained as follows:
Index : This parameter specifies the reference to the vertex.
Size : This parameter specifies the number of components specified in the
vertex. Valid values are 1 to 4.
Type : This parameter specifies the data format. Valid values are BYTE ,
UNSIGNED_BYTE , FLOAT , SHORT , UNSIGNED_SHORT , and FIXED .
Norm : This parameter is used to indicate whether the non-floating data format
type should be normalized when converted to a floating point value. Use the
value false .
Stride : The components of the vertex attribute specified by size are stored
sequentially for each vertex. The Stride parameter specifies the delta
between data for vertex index I and vertex (I + 1). If Stride is 0, the attribute
data for all vertices is stored sequentially. If Stride is >0, then we use the
stride value as the pitch to get vertex data for the next index.
Offset : This is the byte position of the first element of each attribute array in
the buffer. This parameter is used to create interleaved arrays.
Drawing our primitive
We need to understand two drawing functions that we will use frequently. One of
them is the drawArray() function:
gl.drawArrays(Mode, Offset, Count)
The parameters of the drawArray() function are explained as follows:
Mode : This relates to the primitives you would like to render. Valid values are
POINTS , LINES , LINE_STRIP , LINE_LOOP , TRIANGLES , TRIANGLE_STRIP , and
TRIANGLE_FAN .
Offset : This is the starting vertex index in the enabled vertex array.
Count : This is the number of indices to be drawn.
The Mode parameter needs further explanation. When drawing 3D primitives/
models, we pass the vertices array. While drawing, the interconnection of vertices is
decided by the Mode parameter. The following diagram shows the array of vertices in
the actively bound buffer:
[ 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 ]
V0
V1
V2
V3
V4
V5
 
Search WWH ::




Custom Search