I making a small 3dgame which is made as a Silverlight and XNA app, but when I draw the sprites the graphics becomes all wierd.

All my primitive types are rendered correctly, but my 3d models are just wierd

My Draw is like this when silverlight is set to draw

private void OnDraw(object sender, GameTimerEventArgs e)
    // Render the Silverlight controls using the UIElementRenderer

    // Clear the screen to a solid color

    switch (gameState)
        case GameState.ChooseStarter:
            TextBlockStatus.Text = "Find Starting Player";
        case GameState.PlaceBrick:
            TextBlockPlayer.Text = (playerTurn == PlayerTurn.PlayerOne) ? "Player One" : "Player Two";
            TextBlockState.Text = "Place Brick";
            foreach (IGraphicObject obj in _3dObjects)
                obj.Draw(cameraPosition, e);
        case GameState.GiveBrick:
            TextBlockState.Text = "Give Brick";

    // Using the texture from the UIElementRenderer, 
    // draw the Silverlight controls to the screen
    spriteBatch.Draw(elementRenderer.Texture, cameraProjection, Color.White);

This gives me this outputenter image description here

If I comment the spritebatch lines out I get the correct output, except the silverlight text is of course not shown enter image description here

I am not entirely sure what to look for except that zero vector I am giving to the spritebatch, but if thats the source I have no idea what I am supposed to set it as epspecially when its a 2d vector

  • \$\begingroup\$ That worked cool :) that line just isnt in the demo project from msdn :/ \$\endgroup\$
    – Mech0z
    Commented Apr 7, 2012 at 18:02

1 Answer 1


Since the objects appear in the wrong order, this is most likely because the depth buffer is disabled at the time of drawing.

That's actually something that SpriteBatch does and you need to restore it manually. See this link for more information on the problem, as it also covers all the other device states that are also changed by SpriteBatch.

In this particular example, in order to reenable the depth buffer, just add the following line to the end of your OnDraw method:

GraphicsDevice.DepthStencilState = DepthStencilState.Default;
  • \$\begingroup\$ +1, plus you can also tell which render states to set back when calling SpriteBatch.Begin(..) and using the overload with all the render states. That makes the code more self documenting I think. \$\endgroup\$
    – Roy T.
    Commented Apr 7, 2012 at 18:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .