I am some what new to openGL ES and I want to build a simple cube, but seem to be having some problems letting the indice byte buffer that I want to have 4 different TRIANGLE_FANs, how would I go about doing this/ rewriting my code:
public class GLCube{
private float vertices[] = {
1, 1, -1, //p0 - topFrontRight
1, -1, -1, //p1 bottomFront Right
-1, -1, -1, //p2 bottom front left
-1, 1, -1, //p3 front top left
1, 1, 1, //p4 - topBackRight
1, -1, 1, //p5 bottomBack Right
-1, -1, 1, //p6 bottom back left
-1, 1, 1, //p7 front back left
};
private FloatBuffer vertBuff;
private short[] pIndex = {
0, 4, 1, 3, //i0 fan of top front right
5, 4, 1, 6, //i1 fan from bottom right back
2, 1, 3, 6, //i2 fan from bottom left front
7, 3, 4, 6 //i3 fan from top left back
};
private ShortBuffer pBuff;
public GLCube(){
ByteBuffer bBuff = ByteBuffer.allocateDirect(vertices.length * 4);
bBuff.order(ByteOrder.nativeOrder());
vertBuff = bBuff.asFloatBuffer();
vertBuff.put(vertices);
vertBuff.position(0);
ByteBuffer pbBuff = ByteBuffer.allocateDirect(pIndex.length * 2);
pbBuff.order(ByteOrder.nativeOrder());
pBuff = pbBuff.asShortBuffer();
pBuff.put(pIndex);
pBuff.position(0);
}
public void draw(GL10 gl){
gl.glFrontFace(GL10.GL_CW);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertBuff);
gl.glDrawElements(GL10.GL_TRIANGLE_FAN, pIndex.length, GL10.GL_UNSIGNED_SHORT, pBuff);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
}
I assume you have to use GL10.GL_PRIMITIVE_RESTART, but with android, I have don't think this exists...