I'm trying to write a Minecraft Classic custom multiplayer client in XNA 4.0, but I'm completely fixated when it comes to really drawing the world in the game. Each block is a cube in three-dimensional space, and it can have different textures on each side. I read on the Internet and found out that for a cube, textures on each side have different textures, each side needs its own set of vertices. This makes a total of 24 vertices for each cube, and if you have a world consisting of 64 * 64 * 64 cubes (or perhaps even more!), This makes many vertices.
In my source code, I split the texture map that I had into separate textures and applied them before drawing each side of each cube. I was told that this is a very expensive approach, and that I have to store the textures in a single file and just use UV coordinates to map specific sub-textures to the cube. However, this did not significantly affect performance, since the simple number of vertices is simply too large. I was also told to collect the vertices in VertexBuffer and draw them all at once, but this also did not help much, and sometimes throws an exception when the number of vertices exceeds the maximum buffer size. Any attempt that I tried to make cubes share vertices also failed, resulting in massive slowdown and buggy cubes.
I have no idea what to do with this. I'm generally good at programming, but any 3D programming or game development completely eludes me.
Here is the method I use to draw cubes. I have two global lists List<VertexPositionTexture>and List<int>one for vertices and one for indexes. When drawing, I repeat all the cubes in the world and render RenderShape on those that are not empty (for example, Air). The form class that I have is inserted below. The commented code in the AddVertices method is an attempt to make cubes shared vertices. When all the vertices of the cubes are added to the list, data is inserted into VertexBuffer and IndexBuffer, and DrawIndexedPrimitives is called.
, , , , , , , , , . , BasicShape, .
:
http://pastebin.com/zNUFPygP