2014-09-30 164 views
0

我在XNA上的圖元有問題。正如您在鏈接http://imgur.com/12UTd2s中看到的那樣,某些紋理牆壁是透明的,有些則不是。有人可以解釋爲什麼發生這種情況,並幫助我想出一個解決方案?XNA紋理圖元透明

這裏的穿牆聲明中看到:

testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 0, z2), new Vector3(1, 0, 0), new Vector2(0,0))); 
        testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 0, z2 - 50), new Vector3(1, 0, 0), new Vector2(1,0))); 
        testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 20, z2), new Vector3(1, 0, 0), new Vector2(0,1))); 
        testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 20, z2), new Vector3(1, 0, 0), new Vector2(0,1))); 
        testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 20, z2 - 50), new Vector3(1, 0, 0), new Vector2(1,1))); 
        testWall.Add(new VertexPositionNormalTexture(new Vector3(x2, 0, z2 - 50), new Vector3(1, 0, 0), new Vector2(1,0))); 

而這裏的牆的聲明我無法看透:

testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 0, z1 - 50), new Vector3(-1, 0, 0), new Vector2(0,1))); 
        testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 0, z1), new Vector3(-1, 0, 0), new Vector2(0,0))); 
        testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 20, z1 - 50), new Vector3(-1, 0, 0), new Vector2(1,1))); 
        testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 20, z1 - 50), new Vector3(-1, 0, 0), new Vector2(1,1))); 
        testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 20, z1), new Vector3(-1, 0, 0), new Vector2(1,0))); 
        testWall.Add(new VertexPositionNormalTexture(new Vector3(x1, 0, z1), new Vector3(-1, 0, 0), new Vector2(0,0))); 

剔除設置爲無,X2,X1,Z1 ,z2是頂點位置。有什麼想法嗎?

謝謝

回答

2

的原因是不是因爲他們看透,而是因爲你沒有啓用深度緩衝,因此牆會出現在他們繪製順序(底部到頂部) 。

渲染之前你要設置的渲染狀態:

Renderer.GraphicsDevice.DepthStencilState = DepthStencilState.Default; 
+0

它的工作!感謝隊友^^對不起,但我沒有足夠的聲望,以upvote你的答案 – 2014-09-30 21:37:21