3D Models draw bad if draw at the same time 2D Images [SOLVED]

First, sorry for my english.

I’m trying to draw a serie of Model objets and, at the same time, draw 2D images for create an UI.

Whitout code for draw 2D images, 3D models looks fine but when i try to introduce code for draw one image, 3D looks but very bad, without textures, only the color of textures and looks any faces of back side of models.

My code:

(part of class Game1)

protected override void Draw(GameTime gameTime)

        switch (phaseRunningNow)
            case "partida":
            case "mainMenu":
        // Only this 3 lines are for 2D
        spriteBatch.Draw(ImageStorage.GetImage(gandalf.GetNameOfImage()), gandalf.GetPosition(), Color.White);


(part of class Partida)

public void Draw()
for (int i = 0; i < colisionableStaticSprites.Count; i++)
colisionableStaticSprites[i].Draw(camera1.GetViewMatrix(), camera1.GetProjectionMatrix(), ModelStorage.GetModel(colisionableStaticSprites[i].GetNameOfModel()));

Thanks for your time.

Try putting your spriteBatch.Begin() in front of your switch.

Save the GraphicsDevice.DepthStencilState before calling SpriteBatch.Begin(), and set it again after SpriteBatch.End()

1 Like

Setting to default GraphicsDevice.DepthStencilState fix part of problem, with set this before rendering 3D draws the correct faces.

For fix textures also needed to set GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;

In conclusion, for fix all i need to write this code at begining of Draw()

GraphicsDevice.DepthStencilState = DepthStencilState.Default;
GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;

Thank you :wink: