我正在使用分块系统开发块世界,但遇到了 VBO 的错误。我的立方体世界似乎生成随机顶点,但仅在 Radeon HD 6670 上。我现在想知道这是我的代码、LWJGL、OpenGL、6670 还是它的驱动程序出错了,如果这是我可以自己修复的东西. 我有一些截图,但没有一个能正常工作。我在装有 NVidia 卡的笔记本电脑上对其进行了测试,它运行得非常好,我目前正在尝试在 Intel HD 3000 上对其进行测试。谁能告诉我我可能做错了什么?它应该生成一个覆盖 16 * 16 * 16 立方体网格的正方形面。
编辑:它似乎也不适用于 HD 3000,但在 Nvidia 卡上一切正常。
以下是截图:http: //imgur.com/a/Q30Y3
这是创建 VBO 并呈现它的代码:
private void updateChunkVertexArray()
{
thisVertices.clear();
GL15.glDeleteBuffers(thisVBOID);
GL15.glDeleteBuffers(thisTexID);
FloatBuffer bufferedTex = BufferUtils
.createFloatBuffer(buffer.size() * 8 * 6);
thisTexID = VBOHandler.createVBO();
thisVBOID = VBOHandler.createVBO();
for (int i = 0; i < buffer.size(); i++)
{
Vector4f thisVec = buffer.get(i);
float x = (thisVec.getX() + offsetX);
float y = (thisVec.getY() + offsetY);
float z = (thisVec.getZ() + offsetZ);
float posx = 1.0f * size + x * 0.25f;
float posy = 1.0f * size + y * 0.25f;
float posz = 1.0f * size + z * 0.25f;
float negx = -1.0f * size + x * 0.25f;
float negy = -1.0f * size + y * 0.25f;
float negz = -1.0f * size + z * 0.25f;
if (world.getBlock(x, y, z + 1f) == 0)
{
bufferedTex.put(texCoords);
float[ ] frontFace =
{
// Front Face
negx, negy, posz, // Bottom Left
posx, negy, posz, // Bottom Right
posx, posy, posz, // Top Right Of
negx, posy, posz
};
for (int t = 0; t < frontFace.length; t++)
{
thisVertices.add(Float.valueOf(frontFace[t]));
}
//bufferedVertices.put(frontFace);
}
if (world.getBlock(x, y, z - 1f) == 0)
{
bufferedTex.put(texCoords);
float[ ] backFace =
{
// Back Face
negx, negy, negz, // Bottom Left
negx, posy, negz, // Bottom Right
posx, posy, negz, // Top Right Of
posx, negy, negz
};
for (int t = 0; t < backFace.length; t++)
{
thisVertices.add(Float.valueOf(backFace[t]));
}
//bufferedVertices.put(backFace);
}
if (world.getBlock(x, y + 1f, z) == 0)
{
bufferedTex.put(texCoords);
float[ ] topFace =
{
// Top Face
negx, posy, negz, // Bottom Left
negx, posy, posz, // Bottom Right
posx, posy, posz, // Top Right Of
posx, posy, negz
};
for (int t = 0; t < topFace.length; t++)
{
thisVertices.add(Float.valueOf(topFace[t]));
}
//bufferedVertices.put(topFace);
}
if (world.getBlock(x, y - 1f, z) == 0)
{
bufferedTex.put(texCoords);
float[ ] bottomFace =
{
// Bottom Face
negx, negy, negz, // Bottom Left
posx, negy, negz, // Bottom Right
posx, negy, posz, // Top Right Of
negx, negy, posz
};
for (int t = 0; t < bottomFace.length; t++)
{
thisVertices.add(Float.valueOf(bottomFace[t]));
}
//bufferedVertices.put(bottomFace);
}
if (world.getBlock(x + 1f, y, z) == 0)
{
bufferedTex.put(texCoords);
float[ ] rightFace =
{
// right Face
posx, negy, negz, // Bottom Left
posx, posy, negz, // Bottom Right
posx, posy, posz, // Top Right Of
posx, negy, posz
};
for (int t = 0; t < rightFace.length; t++)
{
thisVertices.add(Float.valueOf(rightFace[t]));
}
//bufferedVertices.put(rightFace);
}
if (world.getBlock(x - 1f, y, z) == 0)
{
bufferedTex.put(texCoords);
float[ ] leftFace =
{
// left Face
negx, negy, negz, // Bottom Left
negx, negy, posz, // Bottom Right
negx, posy, posz, // Top Right Of
negx, posy, negz
};
for (int t = 0; t < leftFace.length; t++)
{
thisVertices.add(Float.valueOf(leftFace[t]));
}
//bufferedVertices.put(leftFace);
}
}
float[ ] tempVertices = new float[thisVertices.size()];
for (int i = 0; i < thisVertices.size(); i++)
{
Float f = thisVertices.get(i);
tempVertices[i] = Float.valueOf(f);
}
FloatBuffer bufferedVertices = BufferUtils
.createFloatBuffer(thisVertices.size());
bufferedVertices.put(tempVertices);
bufferedVertices.flip();
bufferedTex.flip();
VBOHandler.bufferData(thisVBOID, bufferedVertices);
VBOHandler.bufferData(thisTexID, bufferedTex);
//And now the rendering code...
public void renderChunk()
{
//GL11.glCallList(chunkDisplayList);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, thisVBOID);
GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, thisTexID);
GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);
GL11.glDrawArrays(GL11.GL_QUADS, 0, thisVertices.size());
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY); // deactivate vertex array
GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
// bind with 0 for normal pointers
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}