Alright i am attempting to make a voxel engine which is similar to Minecraft (Just for fun) I have rendered 4 chunks and I have gone down from 120 FPS to 60 FPS so the way i am doing it isn’t very efficient.
I am using LWJGL 3 using the Open GL 3+
All of my rendering is done using VAOs (Vertex Array Objects)
Each chunk has to go though this method
Rendering code (CHUNK CODE)
private static final int LENGTH = 16;
private Vector3f pos;
private Block[][][] blockData;
public Chunk(float xPos, float yPos, float zPos) {
setPos(new Vector3f(xPos*(Block.BLOCK_WIDTH * LENGTH), yPos*(Block.BLOCK_HEIGHT * LENGTH), zPos*(Block.BLOCK_LENGTH * LENGTH)));
blockData = new Block[LENGTH][LENGTH][LENGTH];
for (int x = 0; x < LENGTH; x++) {
for (int y = 0; y < LENGTH; y++) {
for (int z = 0; z < LENGTH; z++) {
blockData[x][y][z] = new Block(1,(x*Block.BLOCK_WIDTH)+pos.x, (y*Block.BLOCK_HEIGHT) + pos.y,(z*Block.BLOCK_LENGTH) + pos.z);
}
}
}
}
public void render(Model staticObject,StaticShader shader) {
shader.start();
{
GL30.glBindVertexArray(staticObject.getMesh().getVaoID());
{
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
GL20.glEnableVertexAttribArray(2);
for (int x = 0; x < LENGTH; x++) {
for (int y = 0; y < LENGTH; y++) {
for (int z = 0; z < LENGTH; z++) {
Vector3f blockPos = blockData[x][y][z].getPosition();
shader.loadTransformationMatrix(Utils.createTransformationMatrix3D(blockPos, new Vector3f(), new Vector3f(1,1,1)));
GL11.glDrawElements(GL11.GL_TRIANGLES, staticObject.getMesh().getCount(), GL11.GL_UNSIGNED_INT, 0);
}
}
}
GL20.glDisableVertexAttribArray(2);
GL20.glDisableVertexAttribArray(1);
GL20.glDisableVertexAttribArray(0);
}
GL30.glBindVertexArray(0);
}
shader.stop();
}
public Vector3f getPos() {
return pos;
}
public void setPos(Vector3f pos) {
this.pos = pos;
}