Archived

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

SikCiv

Changing D3D8Texture Colorkey runtime

Recommended Posts

I use D3DXLoadTextureFromFileEx to create a colorkeyed texture when I load my graphic files, though sometimes I need to draw the same texture but without colorkeying, and D3DXSprite->Draw() doesnt have a colorkey flag. Is there a way to disable and enable colorkeying after the texture has been created?

  Downloads:  ZeroOne Realm

Share this post


Link to post
Share on other sites
G''day!

I don''t think you can do this with D3DXSprite. One thing that might work (though it''s a hack) would be to call D3DXSprite->Begin() then turn off alphablending. Begin() should turn alphablending on, but if you turn it off manually after Begin (but before you draw) it may work.

Alternately:

1)Don''t use D3DXSprite, it''s simple to make your own interface which will give you more control. My dhEngine has a crude Sprite drawing function. It doesn''t take over any renderstate stuff so you can do it yourself. It also filters out redundant renderstates for greater efficiency. (It''s available on my site).
2)Load 2 copies of the texture, one with colourkey, one without.
3)Lock the texture and do the colourkeying yourself. When you want alpha, change all those pixels to transparent, when you want opaque, lock it and change all the alphas off. There''s an example for programmatically doing the colour key stuff, check out my web page (Computed Alpha Example). It''s probably a better idea to just have 2 copies though (idea #2).



Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites