Skip to main content
gamedev.net
🔒 Locked

Transperancy

Started by EasyGino May 17, 2004 at 6:53 AM 0 replies 450+ views
Original Post
EasyGino
EasyGino
Hello everyone, I''m trying to do a very basic 2d game, just so I can get some concepts down. But I''m struggling to find a decent answer on how to make some of the backgrounds of my 2d textures transperent. The best I found was to pick apart the texture pixel by pixel looking for a certain color. Is this the only way? Thanks, Mike
S1CA
S1CA
If you''re using DirectDraw, then investigate "color keying" - you specify a key colour and tell the Blt(..) that you want to use colour keying - this then tells the graphics card to "pick apart the texture pixel by pixel looking for a certain color". There are DirectDraw samples in the DirectX 7 SDK which demonstrate the use of colour keying.

If you''re using a reasonably up to date version of Direct3D, you can use a texture file format with a range of transparency levels (an alpha channel) - if you use the D3DX functions to load your graphics, most of the work will be done for you; Additionallly functions such as D3DXCreateTextureFromFileEx(..) can convert a colour in the file into an alpha channel transparency value to emulate colour key functionality. How the alpha channel is used is controled by the alpha blending states (such as D3DRS_ALPHABLENDENABLE) and the pixel processing states (SetTextureStageState(..) for the fixed function pipeline and with pixel shaders for the programmable pipeline). If all you need is to emulate colour keying, you can use alpha testing (D3DRS_ALPHATESTENABLE) to determine whether or not a pixel is rendered based on the absolute value of its alpha channel.



Simon O''Connor
Game Programmer &
Microsoft DirectX MVP
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.