我有问题要使用 AndEngine 绘制由 triangle_strip 和 line_strip 绘制的网格。
我正在使用 triangle_strip 生成 2d 地形,三角形是通过这种方式创建的
1 3
|\ |\
| \| \
0 2 4
final int pSegmentsCount = 51;
final int pVertexCount = ( Mesh.VERTEX_SIZE * (pSegmentsCount) );
final float pColor = new Color(0f,0f,0f).getABGRPackedFloat();
final float pSegmentWidth = ( CAMERA_WIDTH/pSegmentsCount );
float[] pBufferData = new float[pVertexCount];
mHeightOffsetCurrent = new float[pVertexCount];
float x = 0f,y = 0f;
for (int i = 0;i<(pSegmentsCount);i++){
if (i%2!=0) { //every 3rd point goes up 2-4-6 , 0-1-3-5 stays down at 0 , x increments every third point
y = 200;
} else {
x = pSegmentWidth*i; //step right by segment
y = 0;
}
mHeightOffsetCurrent[i] = 0; //init default offset
pBufferData[(i * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = x;
pBufferData[(i * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_Y] = y;
pBufferData[(i * Mesh.VERTEX_SIZE) + Mesh.COLOR_INDEX] = pColor;
}
pBufferData[((pSegmentsCount-1) * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_Y] = -300;
final VertexBufferObjectManager VBOM = getVertexBufferObjectManager();
final HighPerformanceMeshVertexBufferObject pMeshVBO = new HighPerformanceMeshVertexBufferObject(VBOM, pBufferData, pVertexCount, DrawType.DYNAMIC, true, Mesh.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT);
pMesh = new Mesh(0, 0,pVertexCount,DrawMode.LINE_STRIP,pMeshVBO);
我正在更改最后一个顶点 y 位置以更好地说明它
这是我得到的,
line_strip
三角带
当我将最后一个点的 Y 设置为 0 时,我仍然看到渐变线到起点。
我做错了什么?为什么最后一个元素与第一个元素连接以及如何解决这个问题?数组由 glDrawArrays 绘制。
public static final int VERTEX_INDEX_X = 0;
public static final int VERTEX_INDEX_Y = Mesh.VERTEX_INDEX_X + 1;
public static final int COLOR_INDEX = Mesh.VERTEX_INDEX_Y + 1;
public static final int VERTEX_SIZE = 2 + 1;