私はVBOs、VAOs、およびIndexesのかなり新しいです。私は単一のキューブをレンダリングできましたが、今はキューブの塊をレンダリングしようとしています。私の目標は、ゆっくりとボクセルエンジンを作ることです。チャンククラスに問題があります。何らかの理由で何も表示されません。誰でも素早く見て、何が間違っているのか分かり、それを私に指摘できますか?乾杯glDrawElementsは何も描画しません
class Chunk {
private IntBuffer vaoID;
private IntBuffer vboID;
private IntBuffer indexID;
public void createChunkVBO() {
FloatBuffer vertices = BufferUtils.createFloatBuffer(16 * 256 * 16 * 3 * 8);
FloatBuffer colors = BufferUtils.createFloatBuffer(16 * 256 * 16 * 4 * 8);
FloatBuffer indices = BufferUtils.createFloatBuffer(16 * 256 * 16 * 4 * 6);
vaoID = BufferUtils.createIntBuffer(1); // Create a buffer for the Vertex Array Object
vboID = BufferUtils.createIntBuffer(1); // Create a buffer for the Vertex Buffer Object
indexID = BufferUtils.createIntBuffer(1); // Create a buffer for the Vertex Indices
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 256; y++) {
for (int z = 0; z < 16; z++) {
System.out.println(x + ", " + y + ", " + z);
vertices.put(x + World.BLOCK_SIZE);
vertices.put(y);
vertices.put(z + World.BLOCK_SIZE);
vertices.put(x);
vertices.put(y);
vertices.put(z + World.BLOCK_SIZE);
vertices.put(x);
vertices.put(y);
vertices.put(z);
vertices.put(x + World.BLOCK_SIZE);
vertices.put(y);
vertices.put(z);
vertices.put(x + World.BLOCK_SIZE);
vertices.put(y + World.BLOCK_SIZE);
vertices.put(z + World.BLOCK_SIZE);
vertices.put(x);
vertices.put(y + World.BLOCK_SIZE);
vertices.put(z + World.BLOCK_SIZE);
vertices.put(x);
vertices.put(y + World.BLOCK_SIZE);
vertices.put(z);
vertices.put(x + World.BLOCK_SIZE);
vertices.put(y + World.BLOCK_SIZE);
vertices.put(z);
colors.put(1f);
colors.put(0f);
colors.put(0f);
colors.put(1f);
colors.put(1f);
colors.put(0f);
colors.put(0f);
colors.put(1f);
colors.put(1f);
colors.put(0f);
colors.put(0f);
colors.put(1f);
colors.put(1f);
colors.put(0f);
colors.put(0f);
colors.put(1f);
colors.put(1f);
colors.put(0f);
colors.put(0f);
colors.put(1f);
colors.put(1f);
colors.put(0f);
colors.put(0f);
colors.put(1f);
colors.put(1f);
colors.put(0f);
colors.put(0f);
colors.put(1f);
colors.put(1f);
colors.put(0f);
colors.put(0f);
colors.put(1f);
indices.put(0 + x * y * z);
indices.put(1 + x * y * z);
indices.put(2 + x * y * z);
indices.put(3 + x * y * z);
indices.put(4 + x * y * z);
indices.put(5 + x * y * z);
indices.put(2 + x * y * z);
indices.put(3 + x * y * z);
indices.put(1 + x * y * z);
indices.put(3 + x * y * z);
indices.put(7 + x * y * z);
indices.put(5 + x * y * z);
indices.put(0 + x * y * z);
indices.put(3 + x * y * z);
indices.put(4 + x * y * z);
indices.put(7 + x * y * z);
indices.put(0 + x * y * z);
indices.put(1 + x * y * z);
indices.put(6 + x * y * z);
indices.put(7 + x * y * z);
indices.put(4 + x * y * z);
indices.put(5 + x * y * z);
indices.put(6 + x * y * z);
indices.put(7 + x * y * z);
}
}
}
glGenVertexArrays(vaoID); // Create an id for the VAO
glBindVertexArray(vaoID.get(0)); // Bind the VAO so it remembers all the Attributes (none right now)
glGenBuffers(vboID); // Create an id for the VBO
glBindBuffer(GL_ARRAY_BUFFER, vboID.get(0)); // Bind the VBO so we can put data into it
glBufferData(GL_ARRAY_BUFFER, 16 * 256 * 16 * 8 * 7 * Float.SIZE, GL_STATIC_DRAW); // We make an empty buffer with a specific size in bytes
// 8 * 7 * sizeof(float)
// 8 = number of vertices, 7 = xyzrgba
glBufferSubData(GL_ARRAY_BUFFER, 0, vertices); // Put the vertices at the beginning of the buffer
glBufferSubData(GL_ARRAY_BUFFER, 16 * 256 * 16 * 8 * 3 * Float.SIZE, colors); // Put the colors after the vertices
glGenBuffers(indexID); // Create an id for the Index Buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexID.get(0)); // Bind the Index Buffer so we can put data into it
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices, GL_STATIC_DRAW); // Store the indices inside the currently bound Index Buffer
}
public void drawChunk() {
glEnableClientState(GL_VERTEX_ARRAY); // Enable the Vertex Array
glEnableClientState(GL_COLOR_ARRAY); // Enable the Color Array
glVertexPointer(3, GL_FLOAT, 0, 0);
glColorPointer(4, GL_FLOAT, 0, 16 * 256 * 16 * 8 * 3 * Float.SIZE); // Position of the colors in the currently bound buffer
glDrawElements(GL_QUADS, 24 * 16 * 256 * 16, GL_UNSIGNED_INT, 0); // Draws the elements from the Index Buffer
}
}
あなたの素晴らしい答えをありがとう!私は実際にFloatBuffersを反転することを忘れてしまった。それを部分的に反転させると、問題が部分的に修正されます。私がglDrawArraysを使うとき、私は四辺形を正しくレンダリングします。しかし、インデックスを使用したいので、1キューブあたり2つのクワッドしかありません。 glDrawElementsは何らかの理由で動作していないようです。私の推測では、私は各キューブのインデックスを追加することを台無しにしています。すべての偉大なヒントをありがとう!あなたが私よりも一般的にOpenGLでもっと経験があるので、私がインデックスをどのように格納するかを見てみる可能性はありますか?とても感謝しております! –
私はあなたのコメントを読んで、まもなくテストします。私は自宅のデスクトップでEclipseとJDKがインストールされている必要があります。私は簡単なテストを行うこともできます...私はあなたに戻って、私がそれを見たときに私の答えを編集します。 –
私は仕事と学校の間でタイムリーにこれに答える時間がないことをお詫びしなければならない。インデックスが初期化された行とglDrawElementsの行の両方でインデックスバッファサイズを修正しました。これはあなたの問題を解決する可能性があります。もしそうでなければ、最初に小さな例から始まり、次にチャンクまであなたの方法を試してみることをお勧めします。例えば、キューブで開始し、次にキューブのライン、次にキューブのグリッド、次いでキューブの塊を含む。 –