Archived

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

bitmap color keying / transparency

This topic is 5618 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok, to start off, this issue caused me to take a long break from game programming cause everytime i looked for a solution, i got response that just wasn''t enough for me to understand how to get the solution to work. please someone help!!! here''s what i''m doing, following Peter Walsh''s instructions in ''Zen of D3D Programming'': 1.) load bitmap to memory w/ GDI''s LoadImage 2.) create a surface using D3D''s CreateImageSurface 3.) load bitmap file to surface w/ D3DXLoadSurfaceFromFile 4.) and finally, load the surface to the backbuffer w/ D3DXLoadSurfaceFromSurface in step 2 i use D3DFMT_A8R8G8B8 for the D3DFORMAT in step 3 i specify an RGB value for color keying in step 4 i do the same again, this time with RGB(0,0,0) since it''s now black from the previous surface load the finished result is all the pixels of the specified color are set to a 32-bit black.... which i expected.... but that doesn''t look good if you are drawing this image over another bitmap unless it''s entirely black... but that''s never the case for me. can someone please help??? in previous posts i was offered the D3DXCreateTextureFromFileEx function as a solution, but i don''t know how to use textures and i can''t find a simple code sample out there to compile to see how it''s used. can the D3DXLoadSurfaceFromSurface function not be used to do color keying? thanks in advance for your help!!!!!!!!!!

Share this post


Link to post
Share on other sites
yknow what? i'm kinda stuck on the same problem. so, hopefully we get a good response. you might want to try d3dxloadsurfacefromfilea. i got that to work, but obviously that won't work if you have a custom image. and then use walsh's copy surface to surface function.

a2k

[edited by - a2k on July 24, 2002 11:18:58 PM]

[edited by - a2k on July 24, 2002 11:19:57 PM]

Share this post


Link to post
Share on other sites
quote:
you might want to try d3dxloadsurfacefromfilea. i got that to work, but obviously that won''t work if you have a custom image. and then use walsh''s copy surface to surface function.



that''s what i''m doing. you got it to work? how? also, what do you mean by custom image? thanks!

Share this post


Link to post
Share on other sites
just to clarify, i''m looking for a way to do color keying using directx to take advantage of the hardware. Peter Walsh provides an algorithm he concocted to go through each pixel individually and replace the specified color with transparency, but it kind of defeats the purpose of using directx, i think and plus, i wouldn''t learn anything this way. it is after all, a book on directx.

Share this post


Link to post
Share on other sites
hmmmm, does anyone just recommend not useing dx8 and going back to 7 since it has support through directdraw??? i''ve scowled the net (yes, with google) and i haven''t come up with anything. why did microsoft make this so difficult?

Share this post


Link to post
Share on other sites
Why not just go through the file before runtime and make the adjustements to the alphachannel? Just make a little utility for it, and run all game images through it(assuming you are using a format that supports an alpha channel, like TGA).
Afterwards you can just use alpha testing(ie hardware) to disregard the transparent pixels.(i dont know exactly how its done in D3D i use OpenGL).

I made such a utility for myself, and it works, and you dont have any runtime overhead.

Share this post


Link to post
Share on other sites