Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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]

Posted

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

 

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

Posted
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.

Posted

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

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

  • 2 weeks later...
Posted
But man oh man is that inefficiant' date=' i hope someone can find a more efficiant way....[/quote']

 

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. ;)

Created by: X

createdbyx@gmail.com

www.createdbyx.com

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...