Opengl es android/openGL立方体与GL_三角形_风扇

Opengl es android/openGL立方体与GL_三角形_风扇,opengl-es,cube,indices,Opengl Es,Cube,Indices,我是openGL ES的新手,我想构建一个简单的多维数据集,但在让indice byte buffer拥有4个不同的TRIANGLE_FANs时似乎遇到了一些问题,我该如何做/重写我的代码: public class GLCube{ private float vertices[] = { 1, 1, -1, //p0 - topFrontRight 1, -1, -1, //p1 bottomFront Right -1, -1, -1, //p2 bottom fr

我是openGL ES的新手,我想构建一个简单的多维数据集,但在让indice byte buffer拥有4个不同的TRIANGLE_FANs时似乎遇到了一些问题,我该如何做/重写我的代码:

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\u PRIMITIVE\u RESTART,但对于android,我认为这是不存在的…

你的假设是正确的,没有
PRIMITIVE\u RESTART
扩展,你无法在一次调用
gldrawerelements
中呈现多个三角形扇形。您可以使用
glmultidrawerelements
,在一个调用中可以绘制多个原语,但是它的使用有点麻烦,我不确定它是否真的比单个三角形列表(尤其是这个简单的立方体)有性能优势

我给你的一般提示是,远离复杂的基本体,如三角形条和扇形,因为它们只用于一些特殊的小几何体(无论如何,在这些几何体中,你不会获得任何性能优势)。更大的通用网格需要更多的努力才能真正从这些基本体类型(如果有的话)中获得优势。只要使用一个简单的索引三角形列表,就可以了

顺便说一句,如果你真的想要一个“复杂”的立方体镶嵌,你可以从一个三角形条带上构建一个立方体,但这个问题的解决方案取决于你或谷歌


编辑:刚刚查阅了GLES规范,似乎在ES中删除了
glMultiDraw…
函数。因此,如果您想在一次调用中绘制多维数据集(这是明智的),则无法使用单个索引三角形列表(或三角形条解决方案)。

嘿,Christian,非常感谢您的回复!正如我所说,我对OpenGL还很陌生,而你深思熟虑的回答也帮了我不少忙。谢谢again@user848162我真的认为这是因为它们的用途非常有限,而且它们在使用即时模式(glBegin()/glEnd())手工编程形状时最有用。这就解释了为什么微软