I'm writing a 3D game which is going to inlcude some dynamic meshes.
For now, my code looks like this :
private float[] mVertices;
private FloatBuffer mVertexBuffer;
public void onDrawFrame(GL10 gl) {
// first clear the screen of any previous drawing
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// initialize the matrix
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
// update the vertex data
for (int vtx = 0; vtx < mVtxCount; ++vtx){
// fill in the x, y and z components of the vertex position
mVertices[vtx * 3] = x;
mVertices[(vtx * 3) + 1] = y;
mVertices[(vtx * 3) + 2] = z;
}
// update the vertex buffer
mVertexBuffer.clear();
mVertexBuffer.put(mVertices);
mVertexBuffer.position(0);
// render the vertex buffer
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
gl.glDrawElements(GL10.GL_LINES, mIndices.length,
GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
}
Here is an easy sample as the index buffer does not change so I only update the vertex position, normal and texture coordinates.
Of course I understand dynamic mesh will always be slower to render than static mesh, but I wonder if the method I use is good or if there is a faster / better way to do this .
