Opengl Java game performance

I use lwjgl with Java to create a block-based 3D game, something like Minecraft. I currently have a Block class that contains the functions void Update () and void Draw (), and I call them in the order Update () and Draw () each cycle of the game loop. The draw function contains texture.bind () when begging to apply the texture to the block, and then have 6 conditions to check if 6 sides need to be displayed respectively. Example:

if(rendertop) GL11.glVertex3f(position.x, position.y, position.z); ..... 

At the moment, it works very well, except when I draw a lot of these blocks, it slows down fps, so the game does not play. After some google search, I found out that there are better ways to draw 3d objects on the screen, and then send each vertex to the graphic map again and again in every draw. I tried using lists, but they seem to have a lot more memory. I made a new list for each side of the block and named it if the side was to be displayed in the same way as in the example above, which means that each block has 6 lists. Here is how I made the lists:

 GL11.glNewList(displayListId, GL11.GL_COMPILE); GL11.glBegin(GL11.GL_QUADS); ...... (Calling GL11.glVertex3f to draw the side) GL11.glEnd(); GL11.glEndList(); 

And I called it this way:

 if(rendertop) GL11.glCallList(displayListId); 

But, as I already said, the game made it very slow, I know that this is probably due to how I implemented it. Another problem when using this method is that you destroy the block needed to remove the display list, and I don't know how to do it.

Can anyone suggest a way to improve performance using display lists or other methods?

+4
source share
2 answers

Use vertex arrays or vertex buffer objects to batch your rendering.

Each VA or VBO must contain (for example) a block of 16x16x16 cubes.

+1
source

If you already have display lists implemented in your code, you probably won't notice a significant increase in speed by putting each block in its own Vertex buffer.

Do what genpfault said, but I would also strongly recommend using octree, quad-tree or some other kind of tree to determine if certain blocks are visible ( definition of a hidden surface ). You will notice a significant increase in productivity.

0
source

All Articles