Original Post
🔒 Locked
Texture Alpha
Advertisement
How would I make a certain color in my texture invisible? For example, if I wanted the color 255 Red 0 Green and 255 Blue to be invisible in my program, how would I do that?
What API(s) are you using?
Ok I found a D3DXCreateTextureFromFileEx function but It will only change the 255 Red, 0 Green and 255 Blue to black. How do I make it a transparent color instead?
D3DXCreateTextureFromFileEx(D3D9Dev, InactiveSprite, 512, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255), NULL, NULL, &Inactive_Sprite);
D3DXCreateTextureFromFileEx(D3D9Dev, InactiveSprite, 512, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255), NULL, NULL, &Inactive_Sprite);
How do I make it a transparent color instead?[/quote]
The documentation may not be very clear. Note that it says it replaces the colorkey with "transparent black" - that's ( 0,0,0,0 ). Black with a zero alpha.
Also, since you'll be rendering for transparency (alpha blending), you should probably use D3DFMT_A8R8G8B8.
EDIT: also, you may want to try a color key of D3DCOLOR_ARGB(255,255,0,255).
EDIT2: I'm not sure how you intend to use the texture, but you might want to consider D3DPOOL_MANAGED.
For anyone else who has this problem, you have to use this code before you render the scene
// Alpha blending
D3D9Dev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); // turn on the color blending
D3D9Dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); // set source factor
D3D9Dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); // set dest factor
D3D9Dev->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); // set the operation
// Alpha blending
D3D9Dev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); // turn on the color blending
D3D9Dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); // set source factor
D3D9Dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); // set dest factor
D3D9Dev->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); // set the operation
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement