spriteBatch and 3D rendering problem?

May 9, 2007 at 4:09 AM
Edited May 9, 2007 at 7:24 AM
Hi all,

How to use spriteBatch with 3D rendering. Please give me sample code.

best regards,
May 9, 2007 at 4:39 PM
Edited May 9, 2007 at 4:40 PM
Try this before you draw your 3D stuff.

GraphicsDevice.RenderState.DepthBufferEnable = true;
GraphicsDevice.RenderState.AlphaBlendEnable = false;
GraphicsDevice.RenderState.AlphaTestEnable = false;

Depending on your 3D content, you may also want to set:

GraphicsDevice.SamplerStates 0 .AddressU = TextureAddressMode.Wrap;
GraphicsDevice.SamplerStates 0 .AddressV = TextureAddressMode.Wrap;

The SamplerStates' 0 should be inside brackets.

Shawn Hargreaves posted a post on his blog about this. http://blogs.msdn.com/shawnhar/archive/2006/11/13/spritebatch-and-renderstates.aspx

Jul 31, 2007 at 12:15 AM
You do this in the game after you have initalized the graphics device manager

you can't set the property of the graphics device directly


graphics = new GraphicsDeviceManager(this);

in game

private void DrawCard(SpriteBatch Batch, Vector2 pos, Texture2D SpriteTexture)
this.graphics.GraphicsDevice.RenderState.DepthBufferEnable = true;
this.graphics.GraphicsDevice.RenderState.AlphaBlendEnable = false;
this.graphics.GraphicsDevice.RenderState.AlphaTestEnable = false;

//draw the sprite
Vector2 origin = new Vector2(32, 32);
Batch.Draw(SpriteTexture, new Vector2(pos.X + 10, pos.Y + 30), null,
Color.White, 0, origin, 1, SpriteEffects.None, 0f);


You can't do this directly like the sample describes for those of you who haven't worked this out already