1
\$\begingroup\$

i have a modelmesh that has a image on it. When i draw the modelmesh i get the image but i also get a black bacground. The image is png and transparent and is added in 3ds max(i don't give it coordinates to be drawn, it sits on the modelmesh). How can i make the black background transparent?

Here is my drawing code:

 foreach (BasicEffect effect2 in modelMesh)
 {
     effect2.DiffuseColor = Color.White.ToVector3();
     effect2.LightingEnabled = true;
     effect2.AmbientLightColor = new Vector3(1, 1, 1);
     effect2.Projection = camera.projectionMatrix;
     effect2.View = camera.viewMatrix;
     effect2.World = transforms[modelMesh.ParentBone.Index] * gameobject.orientation;
     effect2.Alpha = 1;

  }
  modelMesh.Draw();
\$\endgroup\$
4
  • \$\begingroup\$ Can't you switch in property dialog of your model from Basic effect to AlphaTestEffect and also in foreach use AlphaTestEffect instead of BasicEffect? \$\endgroup\$
    – zacharmarz
    Feb 15, 2012 at 13:30
  • \$\begingroup\$ there is a small problem. If i make the changes you said, i get this error:" ErrorThe mesh "s31", using AlphaTestEffect, contains geometry that is missing texture coordinates for channel 0." note that my images are not included in my model, i have them in my LibContent folder along with my model. \$\endgroup\$
    – Alex
    Feb 15, 2012 at 13:44
  • \$\begingroup\$ Ok. You can also try to set RenderState alpha blending to enabled: GraphicsDevice.RenderState.AlphaBlendEnable = true; GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; \$\endgroup\$
    – zacharmarz
    Feb 15, 2012 at 14:06
  • \$\begingroup\$ that looks to me as xna 3.1. i've used this: SharedGraphicsDeviceManager.Current.GraphicsDevice.BlendState = BlendState.AlphaBlend; and it works. Thanks! \$\endgroup\$
    – Alex
    Feb 15, 2012 at 14:39

1 Answer 1

1
\$\begingroup\$

SharedGraphicsDeviceManager.Current.GraphicsDevice.BlendState = BlendState.AlphaBlend; fixed the problem (XNA 4.0)

\$\endgroup\$

You must log in to answer this question.

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