2
votes

I've got a problem. When I try to render my model in XNA 4.0 some places of my texture are trasparent. Is something wrong with texture itself or am I doing something wrong? Model and texture are exported from Blender. I tried to disable color key or premultiply alpha but no luck there.

Screenshot:

http://i43.tinypic.com/2evg56u.jpg

Here are my draw methods:

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.CornflowerBlue, 1.0f, 0);

        DrawModel(model, position);

        spriteBatch.Begin();
        spriteBatch.DrawString(font, "Camera\nX = " + cameraPosition.X.ToString() +
                                     "\nY = " + cameraPosition.Y.ToString() +
                                     "\nZ = " + cameraPosition.Z.ToString(), new Vector2(10, 10), Color.White);
        spriteBatch.DrawString(font, "Look at\nX = " + cameraLookAt.X.ToString() +
                                     "\nY = " + cameraLookAt.Y.ToString() +
                                     "\nZ = " + cameraLookAt.Z.ToString(), new Vector2(10, 150), Color.White);
        spriteBatch.End();

        base.Draw(gameTime);
    }

    void DrawModel(Model model, Vector3 position)
    {
        foreach (ModelMesh mesh in model.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.SpecularColor = new Vector3(0.25f);
                effect.SpecularPower = 16;

                effect.World = Matrix.CreateTranslation(position);
                effect.Projection = projection;
                effect.View = view;
            }

            mesh.Draw();
        }
    }
1
Have you enabled the depth buffer? Have you considered the CullMode state?Blau
Thanks for your reply. I tried CullMode but that doesn't help and I think depth buffer should be enabled by default, however Neil Knigh's answer solved my problem.benderto

1 Answers

0
votes

Check your DepthStencilState as this will change after the SpriteBatch object is called. You may need to reset it Default after the SpriteBatch.End() call.