Game Development Reference
In-Depth Information
if (Vertices != null)
{
m_VertexBuffer.put(Vertices);
m_VertexBuffer.position(0);
m_VertexCount = Vertices.length / m_CoordsPerVertex;
}
// Initialize DrawList Buffer
m_DrawListBuffer = ShortBuffer.wrap(DrawOrder);
}
MeshEx Class Error Debug Function
The function
CheckGLError()
checks for errors that occur after an OpenGL operation by calling the
GLES20.glGetError()
function and by throwing an exception that stops the program and displays an
error (see Listing 4-33).
Listing 4-33. Class Error Debug Function
public static void CheckGLError(String glOperation)
{
int error;
while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR)
{
Log.e("ERROR IN MESHEX", glOperation + " IN CHECKGLERROR() : glError - " + error);
throw new RuntimeException(glOperation + ": glError " + error);
}
}
MeshEx Class Mesh Draw Function
The MeshEx class's function to actually draw the 3D object is called
DrawMesh()
. The function to
perform the required set up is done in
SetUpMeshArrays()
. What actually happens is that triangles
are drawn based on the vertex indices in the
m_DrawListBuffer
variable.
For example, the
m_VertexBuffer
contains eight vertices for the cube in Figure
4-20
.
The
m_DrawListBuffer
contains the values 0, 3, 1, 3, 2, 1. Then the two triangles drawn would
contain v0, v3, v1 for the first triangle and v3, v2, v1 for the second. Together, these would form the
front solid face of the cube.
v4
v7
v3
v0
v6
v1
v2
Figure 4-20.
Drawing triangles