Colorkeying in D3D

Started by
13 comments, last by Possibility 23 years, 9 months ago
It is not antialiasing.
It is bilinear interpolation.
Advertisement
Just use alpha . Give up. I could send you a general purpose functions I modified from SDK samples that loads a texture and sets the alpha if you give up .

I would look to the functions which load the bitmap for problems... I didn''t think D3D could magically know the color key value of a texture (supposing it was loaded correctly and there was no green on the surface)... (that made no sense to anybody but me I bet ), which is what makes me think it might be the bitmap loading functions'' fault.
___________________________Freeware development:ruinedsoft.com
Hey, do you know of any tutorials on how I can set the transparency value of an individual pixel on a bitmap? I guess since colorkeying wont work is that I would need to set them pixels to be totally transparent then. and can that be done on an idividual pixel basis? do you need to have a special file format for that?

Possibility
Ok, i wrote a small little thing to show exactly what I am trying to do. Its on my server at

ftp://test:test@206.145.228.91

its called test.zip and is a small file, and you can see exactly what I am trying to do. Its just a simple texture put on a square surface, you can zoom in and out with the up and down arrow keys.

Possibility
Q. Hey, do you know of any tutorials on how I can set the transparency value of an individual pixel on a bitmap?
A. A bitmap can't hold an alpha channel so finding a tutorial to do so would be unlikely . However, 32bit Targa (.tga) file format is probably what you're looking for, any good image program will let you set the transparency (alpha value) of a Targa image's pixel.

Q. I guess since colorkeying wont work is that I would need to set them pixels to be totally transparent then. and can that be done on an idividual pixel basis?
A. Yep, just lock the DDSurface and access memory directly.

Q. do you need to have a special file format for that?
A. Targa... or you can use bitmaps and just code a color key into the program and not use that color.


Before trying to set alpha values... you should enumerate the texture formats to find a format that has an alpha channel (they can be 1, 2, 4, or 8 bits per pixel). You can either try an set all these bits to zero (fully solid), or all to one (fully transparent), or you can create a DWORD (up to 255) and:

        // This assumes dwPixel is a DWORD value of a locked// surface that has been created with a valid pixel format// after enumerating texturesDWORD dwPixel = *pSurface;// This kills off the least significant bits of your given// value until you have a value within the possible amount.dwAlpha >>= (8 - myDDPixelFormat.dwAlphaBitDepth);// First clear the existing alpha bits of the pixeldwPixel &= (myDDPixelFormat.dwRBitMask |            myDDPixelFormat.dwGBitMask |            myDDPixelFormat.dwBBitMask );// Find out how many bits the alpha needs to be shifted,// so shift right until you find a one in the first bitDWORD dwMask = myDDPixelFormat.dwAlphaMask;for(dwShift = 0; !(dwMask & 1); dwMask >>= 1)     dwShift++;// Then you need to put the alpha value into the correct bits// of the pixel's datadwPixel |= (dwAlpha << dwShift);// Then store the values*pSurface = dwPixel;// Next pixelpSurface++;        


To see examples... in the D3DIM folder, the D3DFrame project, the d3dtext.cpp file...

Edited by - iwasbiggs on July 28, 2000 1:56:10 AM
___________________________Freeware development:ruinedsoft.com

This topic is closed to new replies.

Advertisement