Game Development Reference
In-Depth Information
if (hasTexCoords) {
gl.glEnableClientState(GL10. GL_TEXTURE_COORD_ARRAY );
vertices.position(hasColor ? 7 : 3);
gl.glTexCoordPointer(2, GL10. GL_FLOAT , vertexSize, vertices);
}
}
public void draw( int primitiveType, int offset, int numVertices) {
GL10 gl = glGraphics.getGL();
if (indices != null ) {
indices.position(offset);
gl.glDrawElements(primitiveType, numVertices,
GL10. GL_UNSIGNED_SHORT , indices);
} else {
gl.glDrawArrays(primitiveType, offset, numVertices);
}
}
public void unbind() {
GL10 gl = glGraphics.getGL();
if (hasTexCoords)
gl.glDisableClientState(GL10. GL_TEXTURE_COORD_ARRAY );
if (hasColor)
gl.glDisableClientState(GL10. GL_COLOR_ARRAY );
}
}
Everything stays the same compared to Vertices , except for a few small things:
In the constructor, we calculate
vertexSize differently since the vertex
position now takes three floats instead of two floats.
ï?®
ï?® bind() method, we tell OpenGL ES that our vertices have three rather
than two coordinates in the call to glVertexPointer() (first argument).
We have to adjust the offsets that we set in the calls to
In the
ï?® vertices.position()
for the optional color and texture coordinate components.
That's all we need to do. Using the Vertices3 class, we now have to specify the x, y, and z
coordinates for each vertex when we call the Vertices3.setVertices() method. Everything else
stays the same in terms of usage. We can have per-vertex colors, texture coordinates, indices,
and so on.
An Example
Let's write a simple example called Vertices3Test . We want to draw two triangles, one with z
being −3 for each vertex and one with z being −5 for each vertex. We'll also use per-vertex color.
Since we haven't discussed how to use a perspective projection, we'll just use an orthographic
projection with appropriate near and far clipping planes so that the triangles are in the view
frustum (that is, near is 10 and far is −10). Figure 10-1 shows the scene.
 
Search WWH ::




Custom Search