Hey,
I have been stumped on this bug for ages now. I am making a voxel engine and I am having an issue using textures with my VBO. Everything was up and working just fine when I was just using colors on the cubes but now that I am trying to use textures the program just crashes when it reaches the glDrawArrays call.
public void drawChunk() {
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0L);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOTextureHandle);
GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0L);
GL11.glEnableClientState(GL_TEXTURE_COORD_ARRAY);
GL11.glEnableClientState(GL_VERTEX_ARRAY);
GL11.glDrawArrays(GL11.GL_QUADS, 0, ((24)*activateBlocks));
}
public void createChunk() {
VBOTextureHandle = GL15.glGenBuffers();
VBOVertexHandle = GL15.glGenBuffers();
FloatBuffer vertexPositionData = BufferUtils.createFloatBuffer(((12*6)*activateBlocks));
FloatBuffer vertexTextureData = BufferUtils.createFloatBuffer(((8*6)*activateBlocks));
Random random = new Random();
dirtTexture.bind();
//
// float[] cubeColorArray = new float[24*3];
// for(int i=0; i<24*3; i++) {
// cubeColorArray[i] = random.nextFloat();
// }
for (int x = 0; x < Constants.CHUNK_SIZE; x++) {
for (int z = 0; z < Constants.CHUNK_SIZE; z++) {
for (int y = 0; y < Constants.CHUNK_SIZE; y++) {
if(occlusionCulling(x, y, z)) {
continue;
}
if(blocks[x][y][z].getActive()) {
putVertices((x*2)*Constants.BLOCK_SIZE, (-y*2)*Constants.BLOCK_SIZE, (z*2)*Constants.BLOCK_SIZE, vertexPositionData);
vertexTextureData.put(new float[]{
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f,
});
// vertexTextureData.put(cubeColorArray);
}
}
}
}
vertexPositionData.flip();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexPositionData, GL15.GL_STATIC_DRAW);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
vertexTextureData.flip();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOTextureHandle);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexTextureData, GL15.GL_STATIC_DRAW);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
Any insight would be great. I have been stumped on this for hours.