0
\$\begingroup\$

I am trying to draw a 3D model I made with Blender in Monogame/XNA and this is the result I get when I draw 2 of them on top of each other

1

How can I make it so that the colors don't add up, but the one covers the other ? Here is my drawing code:

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.Black);
    Vector3 modelPosition = new Vector3(-2500, 1500.0f, 0.0f);      
    Vector3 cameraPosition = new Vector3(0.0f, 0.0f, 5000.0f);
    float aspectRatio = (float)graphics.GraphicsDevice.Viewport.Width / 
          (float)graphics.GraphicsDevice.Viewport.Height;
    Vector3 scale = new Vector3(1f, 1, 1);
    Matrix[] transforms = new Matrix[Brick.Bones.Count];
    Brick.CopyAbsoluteBoneTransformsTo(transforms);
    foreach (ModelMesh mesh in Brick.Meshes)
    {
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();
            effect.World = transforms[mesh.ParentBone.Index]*Matrix.CreateScale(scale)*
           Matrix.CreateRotationY(modelRotation)*Matrix.CreateTranslation(modelPosition);
            effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
            effect.Projection = Matrix.CreatePerspectiveFieldOfView(
                  MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
        }
        mesh.Draw();
    }           
    base.Draw(gameTime);
}
\$\endgroup\$
1
\$\begingroup\$

You need to set the blendstate to alpha blending when rendering your objects. You can do it like this:

GraphicsDevice.BlendState = BlendState.AlphaBlend;

This piece of code should go before drawing your mesh.

\$\endgroup\$
  • \$\begingroup\$ thanks it worked, any particular reason this goes before the mesh.Draw() function ? does this reset on every draw ? \$\endgroup\$ – dimitris93 Feb 1 '15 at 14:49
  • \$\begingroup\$ No, it should not reset, but a renderer usually sets more blendstates one after an other, usually for different types of materials. You can set it once in your loadcontent for example, if you won't change it manually between draw calls. \$\endgroup\$ – János Turánszki Feb 1 '15 at 14:52
  • \$\begingroup\$ If i use it on the LoadContent it doesn't change anything, if i use it in my constructor it gives me a null exception \$\endgroup\$ – dimitris93 Feb 1 '15 at 14:54
  • \$\begingroup\$ Are you sure you are not setting the blendstate elsewhere? It could be a spritebatch.begin too. The constructor is not a good place because the GraphicsDevice is not completed yet at that time. \$\endgroup\$ – János Turánszki Feb 1 '15 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.