我是openGL ES的新手,我想构建一个简单的多维数据集,但似乎有一些问题让我想拥有4个不同的TRIANGLE_FAN的索引字节缓冲区,我将如何去做/重写我的代码:
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);
}
}
我假设您必须使用 GL10.GL_PRIMITIVE_RESTART,但是对于 android,我认为这不存在...