Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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();
share|improve this question
    
Can't you switch in property dialog of your model from Basic effect to AlphaTestEffect and also in foreach use AlphaTestEffect instead of BasicEffect? –  zacharmarz Feb 15 '12 at 13:30
    
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. –  Badescu Alexandru Feb 15 '12 at 13:44
    
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; –  zacharmarz Feb 15 '12 at 14:06
    
that looks to me as xna 3.1. i've used this: SharedGraphicsDeviceManager.Current.GraphicsDevice.BlendState = BlendState.AlphaBlend; and it works. Thanks! –  Badescu Alexandru Feb 15 '12 at 14:39
add comment

1 Answer 1

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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