views:

27

answers:

1

I'm using OpenGL ES on Android to draw some shapes, so I have some Model classes to load the vertices etc from an .obj file.

Each model then has a onDrawFrame() method which is called by the Renderer to place it in the scene.

public void onDrawFrame(GL10 gl) {
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glFrontFace(GL10.GL_CCW);
    gl.glCullFace(GL10.GL_BACK);
    gl.glVertexPointer(0, GL10.GL_FLOAT, 0, mVerts);
    gl.glDrawElements(GL10.GL_TRIANGLES, mFaces.capacity(), GL10.GL_UNSIGNED_BYTE, mFaces);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}

My confusion now is where to "reset" the vertex pointer (I think), because if I try to create an arbitrary line from a new glVertexPointer using 2 new verts, and a call to glDrawElements(GL_LINES) using those id's, the line always seems to use verts 0 and 1 from the original data.

Do I need to pre-define all my scene's verts in one master glVertexPointer tracked by the master scene somehow, and have each model just call glDrawElements with a suitable offset? Or do I clear the pointer somehow?

+1  A: 

Not sure if this will solve your problem but your glVertexPointer line should look like this:

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVerts);

Since there are 3 coordinates per vertex. Besides that you should just be able to set a new pointer using your method above.

Frank
Hmm, okay thanks. It must be something borked in the rest of my model class hierarchy then. (The glVertexPointer line is buried a little deeper in my class hierarchy, so is correct in the running code)I'll run up some tests and try and narrow it down.
Cylindric
Yea, are you doing any texturing or color assignments? You should have all of that code together in the onDrawFrame to make it easier to maintain a consistent state, I have definitely run into problems where I have forgotten to disable/enable pointers.
Frank