Game Development Reference
In-Depth Information
gl.glLoadIdentity();
gl.glTranslatef(bobs[i].x, bobs[i].y, 0);
bobModel.draw(GL10. GL_TRIANGLES , 0, 6);
}
fpsCounter.logFrame();
}
That looks pretty much optimal, doesn't it? Well, in fact it is not optimal. First, we can also move
the gl.glMatrixMode() call to the resume() method, but that won't have a huge impact on
performance, as we've already seen. The second thing that can be optimized is a little more subtle.
We use the Vertices class to store and render the model of our Bobs. Remember the
Vertices.draw() method? Here it is one more time:
public void draw( int primitiveType, int offset, int numVertices) {
GL10 gl = glGraphics.getGL();
gl.glEnableClientState(GL10. GL_VERTEX_ARRAY );
vertices.position(0);
gl.glVertexPointer(2, GL10. GL_FLOAT , vertexSize, vertices);
if if(hasColor) {
gl.glEnableClientState(GL10. GL_COLOR_ARRAY );
vertices.position(2);
gl.glColorPointer(4, GL10. GL_FLOAT , vertexSize, vertices);
}
if (hasTexCoords) {
gl.glEnableClientState(GL10. GL_TEXTURE_COORD_ARRAY );
vertices.position(hasColor?6:2);
gl.glTexCoordPointer(2, GL10. GL_FLOAT , vertexSize, vertices);
}
if if(indices! = null ) {
indices.position(offset);
gl.glDrawElements(primitiveType, numVertices, GL10. GL_UNSIGNED_SHORT , indices);
} else {
gl.glDrawArrays(primitiveType, offset, numVertices);
}
if (hasTexCoords)
gl.glDisableClientState(GL10. GL_TEXTURE_COORD_ARRAY );
if if(hasColor)
gl.glDisableClientState(GL10. GL_COLOR_ARRAY );
}
Search WWH ::




Custom Search