Game Development Reference
In-Depth Information
Note
Quad primitives are not supported in OpenGL ES as they are in regular OpenGL. Thus, you will need
two triangles to replace the 1 quad that would have covered all four vertices.
In the
SetUpMeshArrays()
function there are basically three preparation steps for setting up the
vertex position data, vertex texture coordinates (if any), and the vertex normal data (if any). They are
as follows:
1.
Setting the starting position in the
m_VertexBuffer
for the vertex property
being activated using the
position()
function.
2.
Linking the vertex attribute data to a variable in the vertex shader that
handles that vertex attribute by using the
glVertexAttribPointer()
function.
The parameters to this function are
a.
the attribute handle, which is the link to the shader variable;
b.
the size of the attribute in number of coordinates;
c.
the type of the coordinate;
d.
whether the data is normalized, which is false;
e.
the stride in bytes, that is, the length of a single vertex;
f.
the vertex buffer that holds the vertex data.
3.
Enabling the sending of that vertex attribute to the shader by calling
glEnableVertexAttribArray()
with the handle to that shader variable (see
Listing 4-34).
Listing 4-34. Setting Up the Mesh for Drawing
void SetUpMeshArrays(int PosHandle, int TexHandle, int NormalHandle)
{
// Set up stream to position variable in shader
m_VertexBuffer.position(m_MeshVerticesDataPosOffset);
GLES20.glVertexAttribPointer(PosHandle, 3, GLES20.GL_FLOAT, false,
m_MeshVerticesDataStrideBytes, m_VertexBuffer);
GLES20.glEnableVertexAttribArray(PosHandle);
if (m_MeshHasUV)
{
// Set up Vertex Texture Data stream to shader
m_VertexBuffer.position(m_MeshVerticesDataUVOffset);
GLES20.glVertexAttribPointer(TexHandle, 2, GLES20.GL_FLOAT, false,
m_MeshVerticesDataStrideBytes, m_VertexBuffer);
GLES20.glEnableVertexAttribArray(TexHandle);
}