Wil Burton


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.



Re: Textured Quad

Shawn Hargreaves - MSFT


1: you need to set the properties on your effect before you call Begin on it.

2: as well as effect.Begin and End, you need to call effect.CurrentTechnique.Passes[0].Begin.






Re: Textured Quad

Wil Burton

Now the quad doesn't appear at all.

I changed the Draw method to this:

IGraphicsDeviceService graphicService = (IGraphicsDeviceService)m_game.Services.GetService(typeof(IGraphicsDeviceService));

m_effect.Texture = m_texture;

m_effect.TextureEnabled = true;

graphicService.GraphicsDevice.VertexDeclaration = new VertexDeclaration(graphicService.GraphicsDevice, VertexPositionNormalTexture.VertexElements);

m_effect.Begin();

m_effect.CurrentTechnique.Passes[0].Begin();

graphicService.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, m_vertices, 0, 2);

m_effect.CurrentTechnique.Passes[0].End();

m_effect.End();






Re: Textured Quad

Shawn Hargreaves - MSFT

Does the debug DirectX runtime have anything useful to say about this

http://blogs.msdn.com/shawnhar/archive/2007/01/31/debugging-xna-graphics-problems.aspx






Re: Textured Quad

Wil Burton

I get this in DebugView:

[792] D3D9 Helper: Enhanced D3DDebugging disabled; Application was not compiled with D3D_DEBUG_INFO

Can I turn this on with C#





Re: Textured Quad

Shawn Hargreaves - MSFT

Wil Burton wrote:

I get this in DebugView:

[792] D3D9 Helper: Enhanced D3DDebugging disabled; Application was not compiled with D3D_DEBUG_INFO

Can I turn this on with C#

You don't need to - the runtime can still give useful warnings without this.

Does it say anything else after this line






Re: Textured Quad

Wil Burton

Just this:

[2716] Direct3D9: (INFO) :======================= Hal HWVP device selected





Re: Textured Quad

Wil Burton

I was actually able to get it to work by doing this:


graphicService.GraphicsDevice.Textures[0] = m_texture;
graphicService.GraphicsDevice.VertexDeclaration = new VertexDeclaration(graphicService.GraphicsDevice, VertexPositionNormalTexture.VertexElements);
graphicService.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, m_vertices, 0, 2);