I have a Quad class I created and it works...mostly. I want it to be textured, but it seems to use the texture of the last object rendered, my sky sphere. Here is the code:
public void Initialize() {
m_vertices =
new VertexPositionNormalTexture[ 6 ];m_vertices[0].Position =
new Vector3(100, 0, 100);m_vertices[1].Position =
new Vector3(-100, 0, 100);m_vertices[2].Position =
new Vector3(-100, 0, -100);m_vertices[3].Position =
new Vector3(100, 0, 100);m_vertices[4].Position =
new Vector3(-100, 0, -100);m_vertices[5].Position =
new Vector3(100, 0, -100);m_vertices[0].TextureCoordinate =
new Vector2(1, 0);m_vertices[1].TextureCoordinate =
new Vector2(0, 0);m_vertices[2].TextureCoordinate =
new Vector2(0, 1);m_vertices[3].TextureCoordinate =
new Vector2(1, 0);m_vertices[4].TextureCoordinate =
new Vector2(0, 1);m_vertices[5].TextureCoordinate =
new Vector2(1, 1);m_vertices[0].Normal =
Vector3.Up;m_vertices[1].Normal =
Vector3.Up;m_vertices[2].Normal =
Vector3.Up;m_vertices[3].Normal =
Vector3.Up;m_vertices[4].Normal =
Vector3.Up;m_vertices[5].Normal =
Vector3.Up; IGraphicsDeviceService graphicService = (IGraphicsDeviceService)m_game.Services.GetService(typeof(IGraphicsDeviceService));m_effect =
new BasicEffect(graphicService.GraphicsDevice, null);m_effect.EnableDefaultLighting();
}
public override void Draw(Matrix view, Matrix projection) { IGraphicsDeviceService graphicService = (IGraphicsDeviceService)m_game.Services.GetService(typeof(IGraphicsDeviceService));
m_effect.Begin();
m_effect.Texture = m_texture;
m_effect.TextureEnabled =
true;graphicService.GraphicsDevice.VertexDeclaration =
new VertexDeclaration(graphicService.GraphicsDevice, VertexPositionNormalTexture.VertexElements);graphicService.GraphicsDevice.DrawUserPrimitives(
PrimitiveType.TriangleList, m_vertices, 0, 2);m_effect.End();
}
Basically what I'm doing is, create an array of VertexPositionNormalTexture with 6 elements. I set all the points, UV coordinates, and normals. This is used to represent the ground so the normal points up. In Draw() I use DrawUserPrimitives. Before drawing I set the Texture property on the BasicEffect to the texture I want to use. It seems to use the sky sphere texture. What am I doing wrong I have had a hard time finding anything that uses the BasicEffect with a textured quad.