我想在OpenGL中用三角形排序創建三角形網格。我有頂點緩衝區和索引緩衝區。我已經部分成功了,但是在屏幕截圖中可以看到一半網格呈現錯誤。我不知道這是爲什麼。三角形網格,一半是錯誤的
我的代碼是在這裏
float[] vertices = new float[2 * rows * columns];
int counter = 0;
for(int r = 0; r <rows; r++){
for(int c = 0; c < columns; c++){
vertices[counter ++] = (float)r/(rows-1);
vertices[counter ++] = (float)c/(columns -1);
}
}
int[] indices = new int[4 * (rows) * (columns)];
int counter = 0;
for(int r = 0; r < rows; r++){
for(int c =0; c <= columns; c++){
if(r % 2 == 0){
if(c == columns){
indices[counter ++] = (c-1) + (r+1)*columns;
indices[counter ++] = (c-1) + (r+1)*columns;
}else{
indices[counter ++] = c + r * columns;
indices[counter ++] = c + (r+1) * columns;
}
}else{
if(c == columns){
indices[counter ++] = (columns) - c + (r +1) * columns;
indices[counter ++] = (columns) - c + (r +1) * columns;
}else{
indices[counter ++] = (columns - 1) - c + (r + 1) * columns;
indices[counter ++] = r*columns + (columns-1) - c;
}
}
}
}
我建議你閱讀關於原始重啓索引。 – ybungalobill