XNA Rendering Blocks

I am currently building a little game in XNA and found something strange. I want to draw many blocks next to another (1x1x1 with a texture on the side)

So what happens when I do it this lines appear:

When I move the camera the lines change the position or disappear completely. I know this is because the side of the blocks are drawn but i do not know why. Does anybody of you know a solution for my problem? (removing the sides of the cube does not count)

– Katu
Commented Apr 15, 2015 at 18:13
• If your blocks are spatially sorted or you can, otherwise, draw them near-to-far, it's possible that altering DepthBias could alleviate the z-fighting.
– Jon
Commented Apr 16, 2015 at 7:23

(removing the sides of the cube does not count)

Sorry dude, that is what you have to do if you want this to be efficient and work every time. The reason you're getting those lines is slight depth buffer inconsistencies (also known as z-fighting). The sides of the blocks are almost at exactly the same depth as the tops of the nearer blocks.

Ideally, in a block-based game, for performance you really ought to delete non-visible faces. Here's some pseudocode of how you might do it:

// Generate a mesh of a 3D grid of blocks.
Mesh GenerateMesh(Block[, , ] blocks)
Mesh out_mesh;
// Loop through every block.
for x = 0 : blocks.max_x:
for y = 0 : blocks.max_y:
for z = 0 : blocks.max_z:
Block block = blocks[x, y, z];
// Check each face of the block
for face = 0 : 6:
Block neighbor = block.GetNeighbor(face);
// If the neighbor doesn't exist, add the triangles
// from that face.
if (!IsOccupied(neighbor)):