Archived

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

D3DXCreateTextureFromFileEx - Colorkeying.

This topic is 5573 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

Right now the "Search" is diabled, so don''t get mad if this already has been posted a couple of times. I''m using D3D8 for my new 2D engine. So far it works great, to have all these transformations is really fun! However I''m having a problem with transparency. In the D3DXCreateTextureFromFileEx function I can specify a color key, but when I specify pure white for example the source texture''s white parts appear black - not transparent like I wanted them to. This happens for any transparent source color actually. I know I could use alpha blending for this to work, however for me it seems like overkill to add 8 extra bits to an already 24 bit image just to express a simple boolean value. Transparency worked fine without any alpha component in DD7, or must I turn on the alpha blending render state for the normal colorkeying to work properly? I''m in a rush right now, ignore any spelling mistakes. Thank you in advance!

Share this post


Link to post
Share on other sites
I don''t think colorkeying exists in D3D. It''s either alpha blending (with alpha set to 0) or a faster alpha testing. In either case, you need an alpha channel in your textures...

I''m not even sure 24bpp textures are supported. It''s either 16 or 32. So take the best out of it, and have everything 32bpp. All your sprites could have a nice antialiased border at to extra cost (except more work for the artists... but that''s not the point).

----------------
Blaster
Computer game programmer and part time human being
Strategy First - http://www.strategyfirst.com
BlasterSoft - http://www.blastersoft.com

Share this post


Link to post
Share on other sites
All the color key (in that function) does is replace all of that color in the image with transparent black. So if your texture format (ie X8R8G8B8 or whatever) doesn''t have alpha, then all you will see is black. Also make sure that you have the alpha rendering states set correctly.

Share this post


Link to post
Share on other sites
Yes, you need to turn on Alphablending for alphablending to work. As mentioned, the Colourkey argument to CreateTexture just sets the alpha component of appropriate pixels to transparent.

Since you specify a Colourkey, CreateTexture should allocate a texture format with alpha, if you don''t specifically ask for a format, then you''ll have to check what it''s giving you.

If you only want 1-bit alpha, you can request A1R5G5B5 which is a 16-bit format.

There aren''t any 24-bit formats in D3D. There are 32-bit formats where 8 bits aren''t used (X8R8G8B8) and ones where they are used (A8R8G8B8).

Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
Thank you for your help!

I added an alpha channel to my textures in memory - not in the actual files themselves, and I enabled alpha blending as a device state. The colorkeying works now!

Share this post


Link to post
Share on other sites