0
我有一個數組(高度圖),並希望呈現它,但我想爲每個「平方」不同的紋理,我可以做一個VBO頂點和第二個VBO紋理?lwgl紋理多個綁定到一個VBO
將數組拆分成更小的部分是個好主意。 什麼尺寸最好?我讀了32 * 32?或16 * 16像Minecraft的地方?
我想我可以改變數組中的高度,而程序運行和渲染變化,我必須做什麼?
這是我的計劃的一部分:
amountOfVertices = 6 * (data.length - 1) * (data[0].length - 1);
vertexData = BufferUtils.createFloatBuffer(amountOfVertices * vertexSize);
for (int z = 0; z < data.length - 1; z++) {
for (int x = 0; x < data[z].length-1; x++) {
vertexData.put(new float[] { x, data[z+1][x], z+1, }); // Vertex
vertexData.put(new float[] { x+1, data[z+1][x+1], z+1, }); // Vertex
vertexData.put(new float[] { x+1, data[z][x+1], z, }); // Vertex
vertexData.put(new float[] { x+1, data[z][x+1], z, }); // Vertex
vertexData.put(new float[] { x, data[z][x], z, }); // Vertex
vertexData.put(new float[] { x, data[z+1][x], z+1, }); // Vertex
}
}
vertexData.flip();
textureData = BufferUtils.createFloatBuffer(amountOfVertices * texSize);
for (int z = 0; z < data.length - 1; z++) {
for (int x = 0; x < data[z].length-1; x++) {
textureData.put(new float[] { 1f, 1f, }); // Texture Coordinate
textureData.put(new float[] { 1f, 0f, }); // Texture Coordinate
textureData.put(new float[] { 0f, 0f, }); // Texture Coordinate
textureData.put(new float[] { 0f, 0f, }); // Texture Coordinate
textureData.put(new float[] { 0f, 1f, }); // Texture Coordinate
textureData.put(new float[] { 1f, 1f, }); // Texture Coordinate
}
}
textureData.flip();
glBindTexture(GL_TEXTURE_2D, texture.getTextureID());
stone.bind();//bind a texture
vboVertexHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
vboTexCoordHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboTexCoordHandle);
glBufferData(GL_ARRAY_BUFFER, textureData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);