Original Post
Hi,
I''m having problems creating two semi-transparent boxes. This is what I have:
1. Two cubes with a texture on them (the texture is made of several colors, 128x128), that appear one behind the other on screen. The color RED is only of the colors that appear in the texture, and I want ONLY THE RED to become semi-transparent...
2. I set the render states as follows:
ALPHATESTENABLE is TRUE
ALPHABLENDENABLE is TRUE
SRCBLEND is SRCALPHA
DESTBLEND is INVSRCALPHA
Since the texture was created in Paint Brush, I wanted to modify the alpha channel manually, so I did the following:
D3DXCreateTextureFromFileEx( pDev, "red.bmp",
D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_UNKNOWN,
D3DPOOL_MANAGED, D3DX_FILTER_LINEAR, D3DX_FILTER_LINEAR,
0x00000000, NULL, NULL, &MyTex);
// ^^^^^^^ THIS COLORKEY WILL BE IMPORTANT LATER...
MyTex->LockRect(0,&lockedrect,0,0);
// ...loop and put 0x40 as the alpha channel of every texel:
for (i = 0; i < 128; ++i)
for (j=0; j < 128; j++)
{
curr_color = texdata[i*lockedrect.pitch + j];
if (IsRed(curr_color)
{
curr_color = curr_color & 0x00ffffff | 0x40000000;
texdata[i*lockedrect.pitch + j] = curr_color;
}
}
MyTec->UnlockRect(0);
The results I got depend on the value of the ColorKey argument that I passed to CreateTextureFromFileEx:
1. If ColorKey was 0, then nothing happend. The alpha value of 0x40 did not have any affect.
2. If ColorKey was 0 BUT had some non-zero alpha channel (for example: 1,0,0,0), then the red portions of the texture were getting closer to the ambient color as I lowered the alpha value from 0x40 to 0x00.
No matter what, I did NOT see one cube "through" the other in ANY CASE. Any ideas why I can''t make the cubes transparent????