Search code examples
javablocklwjglminecraft

How to optimize a 3D display blocks


I'm trying to develop a Minecraft like.
This is a screenshot of my work :
screenshot
The rendering is satisfactory, but when i'm looking at my FPS, it's horrible : 90 FPS ! I'm rending 4*4* chunks of 16*16*16 blocks.
This is really bad...

To render my world, I render my chunks, which render their blocks.
I'm rendering my blocks like this :

public void renderTop(){
    glTexCoord2f((0)/NBFACES+offs,(0+this.type)/NBBLOCKS+offs); glVertex3f(this.x       , this.y+TAILLE, this.z       );
    glTexCoord2f((1)/NBFACES-offs,(0+this.type)/NBBLOCKS+offs); glVertex3f(this.x+TAILLE, this.y+TAILLE, this.z       );
    glTexCoord2f((1)/NBFACES-offs,(1+this.type)/NBBLOCKS-offs); glVertex3f(this.x+TAILLE, this.y+TAILLE, this.z+TAILLE);
    glTexCoord2f((0)/NBFACES+offs,(1+this.type)/NBBLOCKS-offs); glVertex3f(this.x       , this.y+TAILLE, this.z+TAILLE);
}

public void renderBottom(){
    glTexCoord2f((0+1)/NBFACES+offs,(0+this.type)/NBBLOCKS+offs); glVertex3f(this.x       , this.y       , this.z+TAILLE);
    glTexCoord2f((1+1)/NBFACES-offs,(0+this.type)/NBBLOCKS+offs); glVertex3f(this.x+TAILLE, this.y       , this.z+TAILLE);
    glTexCoord2f((1+1)/NBFACES-offs,(1+this.type)/NBBLOCKS-offs); glVertex3f(this.x+TAILLE, this.y       , this.z       );
    glTexCoord2f((0+1)/NBFACES+offs,(1+this.type)/NBBLOCKS-offs); glVertex3f(this.x       , this.y       , this.z       );
}

 ...

Actualy, i'm rendering blocks face per face if they haven't got neighbors.
So if I walk through the ground, i will not see blocks below the other grass blocks.

Do you know how can i optimize my rendering ? That's too weak :-/
Thx.


Solution

  • Try using backface culling, frustrum culling. That should boost FPS exponentially.