[Solved] View Frustum Culling

So how can you update the “view” of the chunk if you break a block?

update the chunk when a block is broken

But how i use frustum culling then? I f i don’t update the chunks when I move the camera, then the blocks won’t show.
I found something on LWJGL Wiki, but it is under GL3.1, but maybe it will work in GL2.1.

http://www.lwjgl.org/wiki/index.php?title=The_Quad_updating_a_VBO_with_BufferSubData

You need to check every time the camera is moved whether or not a chunk is in the frustum. If it is, you send the chunk to renderer and render it until it is not in the frustum anymore. Only rebuild chunks when a block is removed or it enters the view frustum. If it leaves the screen, save it to disk or delete it or whatever you want to do. But it’s a bad idea to rebuild it every frame. Only rebuild it when you absolutely have to. Otherwise, just have a render method that is constantly running for the chunk.
Also, this:

positionBuffer.put(new float[]{x, y, z + 1f, x + 1f, y, z + 1f, x + 1f, y + 1f, z + 1f, x, y + 1f, z + 1f});
            colorBuffer.put(new float[]{1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0});
            vertexCount += 4;

Should not work. You are creating 3 * 4 vertices per face, not just 4. 3 is the size, 4 is the amount of vertices per face. I don’t know how you’re render function is actually working without that.

And another thing, I’ve never used it, but I don’t think streaming your chunks would be beneficial because you have static terrain. It doesn’t move every frame. The only time it ever changes is when you place or remove a block. If I’m correct, streaming is more for animated models that use VBOs.

It is correct. I am having 4 verices per face, 3 * 4 float numbers per face.
That int is used in

glDrawArrays(GL_QUADS, 0, chunk.vertexCount);

Also, thank you very much for help, that works perfectly for what i am doing. :smiley: