So I have some basic code that renders out a few cubes using a VBO. Now, I want to go a little more advanced and I want to remove and add cubes. I currently render my VBO like this:
private void newChunk(){
glBindBuffer(GL_ARRAY_BUFFER, vbo.vboVHandle);
glVertexPointer(3, GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, vbo.vboCHandle);
glColorPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
for(int x = 0; x < var1; x++){
for(int z = 0; z < var2; z++){
for(int y = 0; y < var3; y++){
glPushMatrix();
glTranslatef(x, y, z);
glDrawArrays(GL_QUADS, 0, 24);
glPopMatrix();
}
}
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
And heres my VBO initialization class:
public class VBO {
public int vboVHandle;
public int vboCHandle;
public float size = 0.5f;
public float color = 0.5f;
public FloatBuffer vertices;
public VBO(){
FloatBuffer colorData = BufferUtils.createFloatBuffer(3 * 4 * 6);
colorData.put(new float[]{
-color, color, color,
color, color, color,
-color, color, color,
color, color, color,
-color, color, color,
color, color, color,
-color, color, color,
color, color, color,
-color, color, color,
color, color, color,
-color, color, color,
color, color, color,
-color, color, color,
color, color, color,
-color, color, color,
color, color, color,
-color, color, color,
color, color, color,
-color, color, color,
color, color, color,
-color, color, color,
color, color, color,
-color, color, color,
-color, color, color
});
colorData.flip();
vertices = BufferUtils.createFloatBuffer(3 * 4 * 6);
vertices.put(new float[] {
-size, -size, size,
size, -size, size,
size, size, size,
-size, size, size,
-size, -size, -size,
-size, size, -size,
size, size, -size,
size, -size, -size,
-size, size, -size,
-size, size, size,
size, size, size,
size, size, -size,
-size, -size, -size,
size, -size, -size,
size, -size, size,
-size, -size, size,
size, -size, -size,
size, size, -size,
size, size, size,
size, -size, size,
-size, -size, -size,
-size, -size, size,
-size, size, size,
-size, size, -size});
vertices.flip();
vboVHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboVHandle);
glBufferData(GL_ARRAY_BUFFER, vertices, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
vboCHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboCHandle);
glBufferData(GL_ARRAY_BUFFER, colorData, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
}
Pretty basic. How would I go about actually removing or adding cubes? I know I have to use glMapBuffer and glUnMapBuffer, but how do I actually make an array of cubes and upload them to the VBO to be rendered? Also, I am currently rendering the cubes like this:
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
for(int x = 0; x < var1; x++){
for(int z = 0; z < var2; z++){
for(int y = 0; y < var3; y++){
glPushMatrix();
glTranslatef(x, y, z);
glDrawArrays(GL_QUADS, 0, 24);
glPopMatrix();
}
}
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
Which obviously renders one cube, just with different coords. How would I render multiple cubes instead of just one?
Thanks for any help!