Hey, this is not a question of performance. I’ve for long been using immidiate openGL, when transfering to VBO for performance purposes, I’ve headed into a issue. Nothing is render!? I can’t see anything.
here’s some code…
Window.java
private void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
game.render();
}
Game.java
public void render() {
ready3D();
render3D();
ready2D();
render2D();
}
//3D
private void ready3D() {
glViewport(0, 0, Display.getWidth(), Display.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(75f, Display.getWidth() / Display.getHeight(), 0.001f, 1000f);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
}
private void render3D() {
world.render(camera);
}
//2D
private void ready2D() {
glClear(1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, Display.getWidth(), Display.getHeight());
glOrtho(0, 1, 0, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
private void render2D() {
}
World.java
public void render(Camera camera) {
chunk.render();
camera.lookThrough();
}
Chunk.java
private void rebuildVBO() {
FloatBuffer vCoords = BufferUtils.createFloatBuffer(size * size * size * (3 * 4 * 6));
FloatBuffer cCoords = BufferUtils.createFloatBuffer(size * size * size * (4 * 4 * 6));
for(int x = 0; x < size; x++) {
for(int y = 0; y < size; y++) {
for(int z = 0; z < size; z++) {
vCoords.put(Shape.createCubeVerticies(x, y, z, 0.5f));
cCoords.put(Shape.getCubeColors());
}
}
}
vCoords.flip();
cCoords.flip();
glBindBuffer(GL_ARRAY_BUFFER, vId);
glBufferData(GL_ARRAY_BUFFER, vCoords, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, cId);
glBufferData(GL_ARRAY_BUFFER, cCoords, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
public void render() {
glBindBuffer(GL_ARRAY_BUFFER, vId);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, cId);
glColorPointer(4, GL_FLOAT, 0, 0L);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_QUADS, 0, size * size * size * (3 * 4 * 6));
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
public static float[] createCubeVerticies(float x, float y, float z, float size) {
return new float[] {
//Bottom face
x, y, z + size,
x + size, y, z + size,
x + size, y, z,
x, y, z,
//Top face
x, y + size, z,
x + size, y + size, z,
x + size, y + size, z + size,
x, y + size, z + size,
//Front face
x, y, z,
x + size, y, z,
x + size, y + size, z,
x, y + size, z,
//Back face
x, y + size, z + size,
x + size, y + size, z + size,
x + size, y, z + size,
x, y + size, z,
//Left face
x + size, y, z,
x + size, y, z + size,
x + size, y + size, z + size,
x + size, y + size, z,
//Right face
x, y, z + size,
x, y, z,
x, y + size, z,
x, y + size, z + size,
};
}
public static float[] getCubeColors() {
return new float[] {
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
};
}
Camera.java
public void lookThrough() {
GL11.glLoadIdentity();
GL11.glRotatef(pitch, 1.0f, 0.0f, 0.0f);
GL11.glRotatef(yaw, 0.0f, 1.0f, 0.0f);
GL11.glTranslatef(x, y, z);
System.out.println(x + ", " + y + ", " + z);
System.out.println(pitch + ", " + yaw);
}
Any help is appritated