Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with Textured Quad's texture showing up black
    primarykey
    data
    text
    <p>I'm trying to draw a textured quad in XNA using the sample code from MSDN <a href="http://msdn.microsoft.com/en-us/library/bb464051.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb464051.aspx</a></p> <p>but instead of drawing it on XY plane i'm drawing it in XZ plane</p> <p>I initialize that quad with this this.quad = new Quad(Vector3.Zero, Vector3.Up, Vector3.Backward, 1, 1);</p> <p>I've tried almost every combination of Normal and Left vector, no matter where the quad is drawn, the quad is completely black. </p> <p>what am i doing wrong here? is the texture's information lost when i'm passing it around? am i mapping the texture positions wrong? </p> <p>ps: Texture, lighting are enabled.</p> <pre><code>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 &lt; 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; } } </code></pre> <p>my draw method:</p> <pre><code> 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&lt;VertexPositionNormalTexture&gt; (PrimitiveType.TriangleList, Vertices, 0, 4, Indexes, 0, 2); } </code></pre> <p>--i solved my problem. something went wrong when i was passing the texture2d across 3 places, now i'm drawing it from the main draw and the texture shows up fine now.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload