Archived

This topic is now archived and is closed to further replies.

chris1234

disp. texture without all pixels of a certain color

Recommended Posts

I finally got a textured transformed and lit vertex on screen for serving purpose as an rpm dial for my racing game in progress but the bitmap image of my rpm dial has black background, which I want to be 100% transparent so I see what''s behind it...I tried using alpha blending but that just makes the entire bitmap/texture (partially) transparent and being a newbie to directx8, and it being along time ago since I last used dx7 I have no idea...so how would I display my texture mapped transformed and lit vertex square to screen without showing every single black pixel of the bitmap/texture??? Chris

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
When you load the bitmap, you have to create a 4th channel (outside of red, green, and blue).. the alpha channel. If you want, say... pure black to be transparent, you can do this:

unsigned char *bitmap = new unsigned char[256*256*3]; //256x256x24bit
unsigned char *newbitmap = new unsigned char[256*256*4]; //256x256x32bit

unsigned long offset;

for (offset=0;offset!=256*256;++offset)
{
if (bitmap[offset+0]==0 && bitmap[offset+1]==0 && bitmap[offset+2]==0)
newbitmap[offset+3]=0; //Invisible
else
newbitmap[offset+3]=255; //Solid
newbitmap[offset+0]=bitmap[offset+0];
newbitmap[offset+1]=bitmap[offset+1];
newbitmap[offset+2]=bitmap[offset+2];
}

Share this post


Link to post
Share on other sites
Alternately, you could draw the dial twice using two different bitmaps with two different blending modes. This actually cuts down on the memory you're using if each bitmap is 8-bpp, as opposed to one 32-bpp bitmap.

The first bitmap should be a black silhouette of your dial with pure middle gray (RGB: 128,128,128) anywhere you want it to appear transparent. Render this image with alpha-blending enabled using D3DBLEND_DESTCOLOR as the source blending mode and D3DBLEND_SRCCOLOR as the destination blending mode.

This will leave a black silhouette on your screen. Then you can render the normal dial (with black background) on top of that using D3DBLEND_ONE for both blending modes. Rendering two separate images will produce more overhead than one 32-bpp image, but it's much easier than manually changing the alpha values of your image. Do whatever works best for you.

If you want to create translucent effects for your dial, play around with the silhouette colors. Just remember that middle gray will always be transparent. Also, this produces faint artifacts in 16-bit color mode. Use 32-bit to get rid of them.

Edited by - Tom on November 6, 2001 1:54:56 PM

Share this post


Link to post
Share on other sites
Actually the 4th to the last parameter of D3DXCreateTextureFromFileExA or D3DXCreateTextureFromFileExW lets you specify a colorkey to use for transparancey, so you do not need to make the alpha channel yourself.

Remember if you use this to make make black the color key, it has to be FF000000 ARGB, and not just 0.

Edited by - invective on November 6, 2001 4:49:55 PM

Share this post


Link to post
Share on other sites