I Can't see clearly now

rifter1818

Junior Contributor
Joined
Sep 11, 2003
Messages
255
Location
A cold dark place
Transparancys not working hence i cant see clearly ha ha ok bad joke. Heres my problem.
Ive loaded a set of textures from a Bitmap and i want all of the Black to be transparant so currently (d3d.dev is my Direct3d device) my settings are as follows (but it doesnt work theres black squares everywhere).
[CS]
d3d.Dev.RenderState.Lighting = false;
d3d.Dev.RenderState.Ambient = Color.White;//redundant but when/if i enable lighting....
d3d.Dev.RenderState.CullMode = Cull.None;
d3d.Dev.RenderState.AlphaBlendEnable = true;
d3d.Dev.RenderState.AlphaTestEnable = true;
d3d.Dev.RenderState.ReferenceAlpha = Color.Black.ToArgb();
d3d.Dev.RenderState.AlphaFunction = Compare.NotEqual;
[/CS]
 
here's what i do while loading the texture:

SpriteImage = TextureLoader.FromFile(dxDevice, ImageName, width,height, D3DX.Default, 0, Format.Unknown, Pool.Default, Filter.Point, Filter.Point, TheTransparentColor.ToArgb)

and before rendering:
dxDevice.RenderState.SourceBlend = Blend.SourceAlpha

dxDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha

dxDevice.RenderState.AlphaBlendEnable =
True


and after rendering (for performance reasons)
dxDevice.RenderState.AlphaBlendEnable = False


 
ThePentiumGuy said:
here's what i do while loading the texture:

SpriteImage = TextureLoader.FromFile(dxDevice, ImageName, width,height, D3DX.Default, 0, Format.Unknown, Pool.Default, Filter.Point, Filter.Point, TheTransparentColor.ToArgb)

and before rendering:
dxDevice.RenderState.SourceBlend = Blend.SourceAlpha

dxDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha

dxDevice.RenderState.AlphaBlendEnable =
True


and after rendering (for performance reasons)
dxDevice.RenderState.AlphaBlendEnable = False


Thats how i normally do it too, but in this case im using from bitmap and i cant find an overload that allows a colorkey.
 
oh, so you've loaded multiple textures from one bitmap..

the only way that i see to get around it is to take the bitmap and save it..
mybitmap.save("sometempfile.bmp")
and then use FromFile, and then delete the bitmap.... horrible memory handling though ;)

pent
 
rifter1818 said:
But man oh man is that inefficiant, i hope someone can find a more efficiant way....

Have you tryied not fiddling with all the D3D flags and simply tried to use a image format that supports transparency like TGA or PNG. If I can avoid working with color keys and transparency flags I uses paint shop pro to create a png image and simply draw out what parts of the image I want to be trans parent. Then when I load my png image into D3D it automatically makes use of the images transparency. No fuss no mess. Just a suggestion... Possibly even more efficient for you to do it that way also. ;)
 
Back
Top