I am trying to make a textured square using the example here .
I can successfully complete the square, but the texture information seems lost. The square takes the color of the main texture, however.
I checked for obvious problems ("Does BasicEffect provide a square for the TextureEnabled property equal to true?") And cannot immediately see the problem.
Code below:
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;
this.quadEffect = new BasicEffect(this.GraphicsDevice, null); this.quadEffect.AmbientLightColor = new Vector3(0.8f, 0.8f, 0.8f); this.quadEffect.LightingEnabled = true; this.quadEffect.World = Matrix.Identity; this.quadEffect.View = this.View; this.quadEffect.Projection = this.Projection; this.quadEffect.TextureEnabled = true; this.quadEffect.Texture = someTexture; this.quad = new Quad(Vector3.Zero, Vector3.UnitZ, Vector3.Up, 2, 2); this.quadVertexDecl = new VertexDeclaration(this.GraphicsDevice, VertexPositionNormalTexture.VertexElements);
public override void Draw(GameTime gameTime) { this.GraphicsDevice.Textures[0] = this.SpriteDictionary["B1S1I800"]; this.GraphicsDevice.VertexDeclaration = quadVertexDecl; quadEffect.Begin(); foreach (EffectPass pass in quadEffect.CurrentTechnique.Passes) { pass.Begin(); GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>( PrimitiveType.TriangleList, beamQuad.Vertices, 0, 4, beamQuad.Indexes, 0, 2); pass.End(); } quadEffect.End(); }
source share