Hi,
I'm trying to draw a few of my meshes with varying opacity (MDX 1.1). I read a few tutorials and such, set the alpha value of the mesh's material's diffuse color, and turned on alphablending before drawing. Yet, the meshes appear 100% black (on a black background). I spent some time tweaking the render and texture states, but I can't seem to get the model to appear 50% transparent.
Here's my load mesh function. As you can see, I'm manually resetting the diffuse color on-load to give the model 50% alpha.
private static Mesh loadMesh(Device d, string file, ref Material[] meshMats, ref Texture[] meshTexts)
{
ExtendedMaterial[] mtrl;
Mesh tempMesh = Mesh.FromFile(file, MeshFlags.SystemMemory, d, out mtrl);
if ((mtrl != null) && (mtrl.Length > 0))
{
meshMats = new Material[mtrl.Length];
meshTexts = new Texture[mtrl.Length];
for (int i = 0; i < mtrl.Length; i++)
{
meshMats = mtrl.Material3D;
meshMats.Ambient = meshMats.Diffuse;
meshMats.Diffuse = Color.FromArgb(127, meshMats.Diffuse);
if ((mtrl.TextureFilename != null) && (mtrl.TextureFilename != string.Empty))
meshTexts = TextureLoader.FromFile(d, @"..\..\Models\" + mtrl.TextureFilename);
}
}
return tempMesh;
}
Here's my draw function, where I made a feeble attempt to set the correct render and texture states...
public void Draw()
{
device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.DestinationAlpha;
device.SetTextureStageState(0, TextureStageStates.AlphaOperation, true);
device.SetTextureStageState(0, TextureStageStates.AlphaArgument1, true);
device.SetTextureStageState(0, TextureStageStates.AlphaArgument2, true);
for (int i = 0; i < materials.Length; i++)
{
device.Material = materials;
device.SetTexture(0, textures);
mesh.DrawSubset(i);
}
device.RenderState.AlphaBlendEnable = false;
}
If it makes a difference to the solution of my problem, I have lighting enabled and have various point lights in the scene.
What am I missing? :(