XNA Game (having issues! xD obviously)

Started by
4 comments, last by BlenMiner 9 years, 2 months ago

I am not doing any culling since I want to fixe this issue first!

This is my very FIRST time using xna (yeah I know its dead) actually my first day so yeah i am in a learning process.

Back on topic my issue is this:

From one side the chunk renders right http://oi62.tinypic.com/20fuqb.jpg

but from the other side the same chunk renders like this: http://oi57.tinypic.com/9qadlc.jpg

Advertisement

It's really hard to tell anything from those screenshots since the lighting is so flat, but it looks like you have the winding order incorrect in some of your cubes vertices.

I think they are right.. the faces underneath are overlayed with the faces on top for some reason..


const float tBlockSize = 1f / 16f;
        private void TopFace(int xOffset,int yOffset, int zOffset)
        {
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));

            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));
        }
        private void BottomFace(int xOffset, int yOffset, int zOffset)
        {
            yOffset--;

            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0)));

            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
        }
        private void FrontFace(int xOffset, int yOffset, int zOffset)
        {
            yOffset--;

            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));

            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));
        }
        private void BackFace(int xOffset, int yOffset, int zOffset)
        {
            yOffset--;
            zOffset++;

            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0)));

            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 1 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
        }
        private void RightFace(int xOffset, int yOffset, int zOffset)
        {
            yOffset--;

            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0)));

            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
        }
        private void LeftFace(int xOffset, int yOffset, int zOffset)
        {
            yOffset--;
            xOffset++;

            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));

            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 0 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 1 + zOffset), Color.White, new Vector2(0 + tBlockSize, 0 + tBlockSize)));
            vertexList.Add(new VertexPositionColorTexture(new Vector3(worldPos.X + 0 + xOffset, worldPos.Y + 1 + yOffset, worldPos.Z + 0 + zOffset), Color.White, new Vector2(0, 0 + tBlockSize)));
        }

No one? :p

Check if depth test enabled.

Yeah my issue was that i needed to reset these 2 variables to this:

GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
still learning! xd

This topic is closed to new replies.

Advertisement