2011-11-11 111 views
1

我試圖使用從MSDN http://msdn.microsoft.com/en-us/library/bb464051.aspx與紋理四的紋理顯示出來的問題黑

示例代碼繪製紋理四在XNA但不是繪製它XY平面上我畫它在XZ平面

我用這個 this.quad初始化這個四元組= new new(Vector3.Zero,Vector3.Up,Vector3.Backward,1,1);

我已經嘗試了幾乎每種正常和左向量的組合,無論在哪裏繪製四邊形,四邊形都是完全黑色的。

我在這裏做錯了什麼?當我傳遞它時,紋理的信息會丟失嗎?我映射的紋理位置錯了?

ps:紋理,照明已啓用。

public class Quad 
{ 
    public VertexPositionNormalTexture[] Vertices; 
    public Vector3 Origin; 
    public Vector3 Up; 
    public Vector3 Normal; 
    public Vector3 Left; 
    public Vector3 UpperLeft; 
    public Vector3 UpperRight; 
    public Vector3 LowerLeft; 
    public Vector3 LowerRight; 
    public int[] Indexes; 


    public Quad(Vector3 origin, Vector3 normal, Vector3 up, 
      float width, float height) 
    { 
      this.Vertices = new VertexPositionNormalTexture[4]; 
      this.Indexes = new int[6]; 
      this.Origin = origin; 
      this.Normal = normal; 
      this.Up = up; 

      // Calculate the quad corners 
      this.Left = Vector3.Cross(normal, this.Up); 
      Vector3 uppercenter = (this.Up * height/2) + origin; 
      this.UpperLeft = uppercenter + (this.Left * width/2); 
      this.UpperRight = uppercenter - (this.Left * width/2); 
      this.LowerLeft = this.UpperLeft - (this.Up * height); 
      this.LowerRight = this.UpperRight - (this.Up * height); 

      this.FillVertices(); 
    } 

    private void FillVertices() 
    { 
      Vector2 textureUpperLeft = new Vector2(0.0f, 0.0f); 
      Vector2 textureUpperRight = new Vector2(1.0f, 0.0f); 
      Vector2 textureLowerLeft = new Vector2(0.0f, 1.0f); 
      Vector2 textureLowerRight = new Vector2(1.0f, 1.0f); 

      for (int i = 0; i < this.Vertices.Length; i++) 
      { 
        this.Vertices[i].Normal = this.Normal; 
      } 

      this.Vertices[0].Position = this.LowerLeft; 
      this.Vertices[0].TextureCoordinate = textureLowerLeft; 
      this.Vertices[1].Position = this.UpperLeft; 
      this.Vertices[1].TextureCoordinate = textureUpperLeft; 
      this.Vertices[2].Position = this.LowerRight; 
      this.Vertices[2].TextureCoordinate = textureLowerRight; 
      this.Vertices[3].Position = this.UpperRight; 
      this.Vertices[3].TextureCoordinate = textureUpperRight; 

      this.Indexes[0] = 0; 
      this.Indexes[1] = 1; 
      this.Indexes[2] = 2; 
      this.Indexes[3] = 2; 
      this.Indexes[4] = 1; 
      this.Indexes[5] = 3; 
    } 
} 

我的繪製方法:

 graphicsDevice.BlendState = BlendState.AlphaBlend; 

     Effect.World = Matrix.Identity; 
     Effect.View = Camera.View; 
     Effect.Projection = Camera.Projection; 
     Effect.TextureEnabled = true; 
     Effect.Texture = OilTexture; 

     Effect.EnableDefaultLighting(); 
     Effect.PreferPerPixelLighting = true; 


     foreach (EffectPass pass in oilEffect.CurrentTechnique.Passes) 
     { 
      pass.Apply(); 

      graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture> 
        (PrimitiveType.TriangleList, 
        Vertices, 
        0, 
        4, 
        Indexes, 
        0, 
        2); 
     } 

--i解決我的問題。當我將texture2d傳遞給3個位置時,出現了一些問題,現在我正在從主要繪製中繪製紋理,現在紋理顯示正常。

+0

你說照明已啓用,但你是否設置了照亮四方的燈?請發佈渲染四邊形的代碼。 –

+1

你可以請你的解決方案作爲答案,並接受它,而不是編輯你的問題。這將從每個人的未答覆列表中刪除它。 –

回答

0

有很多原因四可能是黑色的,這裏有幾件事我喜歡做調試:

  • 關閉閃電和VERT顏色設定,以確保四的方向作爲我期望。
  • 如果可能,請使用樣本紋理以確保紋理數據的有效性(由於格式不符合我的預期,因此不同版本的管道失敗 加載紋理時遇到很多問題DDS有 子格式如果你正在自己的數據)
  • 檢查一旦你翻轉閃電要確保你有所有頂點設置避雷值
  • 嘗試關閉質感與閃電關閉
  • 可見可能會非常棘手將系統的環境值設置爲全部

如果這些工作都不密切關注您正在傳遞頂點閃電值的區域,頂點正常值以及光照到硬件。

+0

我在模擬程序中運行該示例,顯示正常。 我不認爲我通過任何頂點閃電值,我應該在哪裏設置? – Karis

+0

我只是在談論.Normal值。您正在使用設置正確傳遞它。 – TurqMage