我試圖使用從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個位置時,出現了一些問題,現在我正在從主要繪製中繪製紋理,現在紋理顯示正常。
你說照明已啓用,但你是否設置了照亮四方的燈?請發佈渲染四邊形的代碼。 –
你可以請你的解決方案作爲答案,並接受它,而不是編輯你的問題。這將從每個人的未答覆列表中刪除它。 –