I was working on a block world with a chunking system and I encountered a bug with VBOs. My cube world seems to generate random vertices, but only on the Radeon HD 6670 and HD 3000 that I’ve tested it on. I’m now wondering if this is my code, LWJGL, OpenGL, the 6670/3000, or their drivers bugging out, and if it is something I can fix myself. I have a few screenshots, though none of it working correctly. I tested it on a laptop with an NVidia card in it and it ran perfectly fine. Can anyone tell me what I may be doing wrong? It is intended to generate a square of faces that covers a 16 * 16 * 16 cube grid.
Here are the screenshots: http://imgur.com/a/Q30Y3
And here’s the code that creates the VBO and renders it:
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);
}