android opengl跳过面

android opengl跳过面,android,opengl-es,Android,Opengl Es,我正在屏幕上画一个简单的三角形。这是我的对象类: public class GLObj { private FloatBuffer vertBuff; private ShortBuffer pBuff; private float vertices[] = { 0f, 1f, 0, // point 0 1f, -1f, 0, // point 1 -1f, -1f, 0 // point 3 }; private sh

我正在屏幕上画一个简单的三角形。这是我的对象类:

public class GLObj
{
private FloatBuffer     vertBuff;
private ShortBuffer     pBuff;

private float           vertices[] = 
{
     0f,  1f, 0, // point 0
     1f, -1f, 0, // point 1
    -1f, -1f, 0  // point 3
};

private short[]         pIndex = { 0, 1, 2 };

public GLObj()
{
    ByteBuffer bBuff = ByteBuffer.allocateDirect(vertices.length * 4); // each point uses 4 bytes
    bBuff.order(ByteOrder.nativeOrder());
    vertBuff = bBuff.asFloatBuffer();
    vertBuff.put(vertices);
    vertBuff.position(0);

    // #### WHY IS THIS NEEDED?! I JUST WANT TO DRAW VERTEXES/DOTS ####
    ByteBuffer pbBuff = ByteBuffer.allocateDirect(pIndex.length * 2); // 2 bytes per short
    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);

    // ### HOW TO PASS VERTEXT ARRAY DIRECTLY WITHOUT FACES?? ###
    gl.glDrawElements(GL10.GL_POINTS, pIndex.length, GL10.GL_UNSIGNED_SHORT, pBuff);

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
}

我的问题是:为了理解OpenGL,我想跳过面,只在屏幕上显示顶点。问题是我不明白如何只将顶点传递给GLD元素函数


我是否“必须”定义了“面”(pIndex变量)才能显示顶点,即使它们是点?

否,只绘制点不需要索引数组。使用
glDrawArrays()
而不是
glDrawElements()
glDrawElements()
用于索引几何体,而
glDrawArrays()
仅绘制一系列顶点

在您的示例中,将
glpaurements()
调用替换为:

gl.glDrawArrays(GL10.GL_POINTS, 0, vertices.length / 3);

请注意,最后一个参数是顶点计数。由于
顶点
数组包含每个顶点的3个坐标,因此需要将数组的长度除以3以获得顶点计数。

非常感谢!!正是我所需要的!:)