0

I'm making a Minecraft like game using OpenGL and I wonder, what is the best solution to make a flexible rendering without perfomance loss. I mean there are different types of blocks with different ways of drawing: usual blocks are just simple cubes with textures, stairs are more complex and liquid blocks like water and lava need texture update. I have a chunk with display list. Every block has it's own type (byte value). According to this value I can find "full" block representation (it is common for all blocks of same type and contains name, draw method and additional info). Now I need to remove rendering invisible faces (if block has a neighbour at the left, we don't need to draw it's left face). But it means I need to pass 6 arguments to the drawing method (or an array, or a mask). Is it a good way of drawing, or I have choosen a dumb solution? What can you recommend for drawing different types of blocks in it's own way?

for(int x = 0; x < 16; x++){
        for(int y = 0; y < 128; y++){
            for(int z = 0; z < 16; z++){    
                GL11.glPushMatrix();
                    GL11.glTranslatef(x, y, z);
                    BlockTypes.getBlockType(blocks[x][y][z].type).draw();                   
                GL11.glPopMatrix();
            }
        }
    }       
Pavel Rudko
  • 248
  • 2
  • 8

1 Answers1

0

I recommend using a VBO for each chunk and shaders, rather than a display list and the fixed pipeline(which is deprecated actually).

Using a VBO gives multiple advantages. It lets you use shaders, giving far more flexibility than fixed pipeline. With shaders you can send off texture data, colour data, etc. separately from vertex/index data. As well, VBOs are faster in general.

One way VBOs give more flexibility is with water and lava, which require textures updates can be called separately from the buffering, reducing need to rebuffer the entire chunk.

As for the invisible face detection, I believe that is the only way to do it. Instead of passing 6 arguments, just pass the chunk to the method. You can also make a method that retrieves the blocks surrounding the block you are checking.