Question

Well, I am creating a minecraft terrain thing just for the heck of it. The problem I have is that if you look on a certain angle some faces which are actually behind others are drawn in front of them, thus not showing the actual ones which are there. Like minecraft I have the terrain seperated into regions, and when the vertexbuffer is built, only the "outside" faces are shown. It is also for some reason is not drawing the very top nor the left blocks. In addition to all of these problems faces seem to be overlapping ie (only half of a face can be seen)

Here is what it looks like (note I am only drawing the top faces because I have to fix the others up): http://s1100.photobucket.com/albums/g420/darestium/?action=view&current=minecraftliketerrain.png

I am also drawing all the regions in one go with the following method (i'm using reimer's effect file until I can write my own :):

public void Draw(Player player, World world) 
    { 
        effect.CurrentTechnique = effect.Techniques["TexturedNoShading"]; 
        effect.Parameters["xWorld"].SetValue(Matrix.Identity); 
        effect.Parameters["xProjection"].SetValue(player.Camera.ProjectionMatrix); 
        effect.Parameters["xView"].SetValue(player.Camera.ViewMatrix); 
        effect.Parameters["xCamPos"].SetValue(player.Camera.Position); 
        effect.Parameters["xTexture"].SetValue(world.TextureAlias.SheetTexture); 
        effect.Parameters["xCamUp"].SetValue(player.Camera.UpDownRotation); 

        for (int x = 0; x < world.regions.GetLength(0); x++) 
        { 
            for (int y = 0; y < world.regions.GetLength(1); y++) 
            { 
                foreach (EffectPass pass in effect.CurrentTechnique.Passes) 
                { 
                    pass.Apply(); 


                    Region region = world.regions[x, y]; 

                    if (player.Camera.BoundingFrustum.Contains(region.BoundingBox) != ContainmentType.Disjoint) 
                    { 
                        device.SetVertexBuffer(region.SolidVertexBuffer); 
                        //device.Indices = region.SolidIndices; 
                        device.DrawPrimitives(PrimitiveType.TriangleList, 0, region.VertexCount); 
                        //device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, region.VertexCount, 0, region.SolidIndices.IndexCount / 3); 
                    } 
                } 
            } 
        } 
    } 

Help would be much appreciated thanks :)

Was it helpful?

Solution

Looks like the Z-buffer is disabled. Try setting:

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

The issue with it not drawing the top/left blocks, that you mention, is probably an issue to do with your vertex buffer generation code (if so, try asking another question specifically about that issue).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top