SpriteBatch.Begin() making my model not render correctly
Posted
by
manning18
on Game Development
See other posts from Game Development
or by manning18
Published on 2012-07-04T06:34:09Z
Indexed on
2012/07/04
9:23 UTC
Read the original article
Hit count: 251
XNA
|spritebatch
I was trying to output some debug information using DrawString when I noticed my model suddenly was being rendered like it was inside-out (like the culling had been disabled or something) and the texture maps weren't applied
I commented out the DrawString method until I only had SpriteBatch.Begin() and .End() and that was enough to cause the model rendering corruption - when I commented those calls out the model rendered correctly
What could this be a symptom of? I've stripped it down to the barest of code to isolate the problem and this is what I noticed.
Draw code below (as stripped down as possible)
GraphicsDevice.Clear(Color.LightGray);
foreach (ModelMesh mesh in TIEAdvanced.Meshes)
{
foreach (Effect effect in mesh.Effects)
{
if (effect is BasicEffect)
((BasicEffect)effect).EnableDefaultLighting();
effect.CurrentTechnique.Passes[0].Apply();
}
}
spriteBatch.Begin();
spriteBatch.DrawString(spriteFont, "Camera Position: " + cameraPosition.ToString(), new Vector2(10, 10), Color.Blue);
spriteBatch.End();
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
TIEAdvanced.Draw(Matrix.CreateScale(0.025f), viewMatrix, projectionMatrix);
© Game Development or respective owner