0
我正在屏幕上繪製一個簡單的三角形。這是我的對象類:android opengl skip faces
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的我想跳過的面孔,只是在屏幕上顯示的頂點。問題是我不明白如何僅將頂點傳遞給glDrawElements函數。
爲了顯示頂點,即使它們是點,我是否必須定義「面」(pIndex變量)?
非常感謝!正是我需要的! :) – user3578847 2014-10-04 16:04:02