Archived

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

D3D8, Sprites, and Color Keying

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

This have been asked here a million time, and I still cant get a clear answer. Ive written a small 2D engine with D3D using D3DXSprites and Color Keying (when the texture is created, specificy the transparent color). I read some places this is ok, other have said it will not work on a lot of video cards. Ive tested my engine on about 10-15 computers and about 3-4 do NOT support color keying (so I have black boxes around my sprites). Ive been told I need to start using an alpha channel. And to do that I'll need to create another bitmap (black and white) to use transparency. But I dont want to do that. Thats too much tedious work. Having to get through a few hundred images and make another image just for the transparent outline. Not only that but it would take up a lot of memory, that just doesnt seem necessary. All I want to do is ignore magenta in my images (255,0,255). It was easy in DirectDraw... we does it have to be so complicated here On top of that, Im not even 100% sure I can use the alpha channel with D3DXSprites. Do I have to go through vertex buffers, world matrix's, and all that stuff? I just want a simple 2D engine *sob*sob* Im looking for a practical solution. I thought it wouldnt be hard to write a function that read a normal bitmap, and created another images (dds perhaps?) with the appropriate alpha channel according to the orig. bitmap's magenta pixels. This would cause load times to increase, but would at least cut down on tedious work (plus I could just save off the .dds and delete the bmp and only do it one time) Ive also heard .tga's and .png's support alpha channels. Thats great, but Im still thinking it would be a lot of work to have to go back through each image (we are making 2D renderings of 3D models for our characters) and create an alpha channel. Unless 3D studio max can do it automatically (I dunno, I cant even draw a box with that thing) What do you people do? Im sure someone has found a usefull, practical solution. Im really looking for maximum compatibility. I dont want to exclude people w/ older video cards, I dont even want them to have to update their drivers. It seems almost like it would be better to go back to DirecDraw w/ DX7.... Ratman --------------- Ratfest.org Edited by - ratman on June 26, 2001 12:53:24 PM

Share this post


Link to post
Share on other sites
Well this works on my work computer (which didnt work in my engine). I''ll try it on my other computers when I get home and let you know how it works.

Share this post


Link to post
Share on other sites
Some cards simply dont support color keying, but they are only the older ones such as the TNT, some voodoos, and some onboard intel chipsets. Basically if the card doesnt have colorkeying then its too slow to use 3D in the first place.

Download my D3DXSprite 2D wrapper with source at:

  Game Download  ZeroOne Realm

Share this post


Link to post
Share on other sites
I dont buy that though, not at all. A TNT 1 can play Quake 3, it should be able to run my stupid 2D engine.

Anyone have any way else they do it?

Share this post


Link to post
Share on other sites
I''ve noticed the same odd thing, in a game called Redline (Not Redline Racers, mind you...)

In the main menu, the cursor has a black box around it. But in-game, colorkeys work fine. Maybe their colorkeys in-game are actually alphamaps?

The black box appeared when I used my Voodoo2, but not with my TNT2, in my old computer... and it still happens in my new one, with a 32mB GeForce2... But with all three, in-game transparency worked. Hmmm...

Share this post


Link to post
Share on other sites
If you take a look at the D3DX Sprite Interface provided my Microsoft you will see that its Draw Member takes in a LPDIRECT3DTEXTURE8 object. You can create this object using the D3DXCreateTextureFromFileEx function. In this call you can specify a D3DCOLOR object or by using the macro D3DCOLOR_ARGB. This way, for your case you would use D3DCOLOR_ARGB(255,255,0,255) for the color key value. Give this a try.

-----------------------------
kevin@mayday-anime.com
http://dainteractive.mayday-anime.com

Share this post


Link to post
Share on other sites
grasshopa: this is the way Im doing it, but this way is not garunteed to work.

Im doing some more tests today, I''ll let you know what I get.

Share this post


Link to post
Share on other sites
Ok heres what I got:

Using D3DXCreateTextureFromFileEx and passing it the parameter: D3DCOLOR_RGBA(255,0,255,255) I will get transparency (for magenta) when I am in a D3DFMT_A1R5G5B5 pixel format. Not everycard will support this format in hardware. But I was able to get it to run in software. The problem is software is _incredibly_ slow.

Does this sound right? Is there an easy fix for this, or am I gonna have to write code for each pixel format (if thats even possible)?

So I guess I should use Alpha Channels/Testing. Can I do this with D3DXSprites?

ratman

---------------
Ratfest.org

Edited by - ratman on June 28, 2001 1:24:02 PM

Share this post


Link to post
Share on other sites
Now I have always used straight black and have had no issues. Have you tried it with a different color?


-----------------------------
kevin@mayday-anime.com
http://dainteractive.mayday-anime.com

Share this post


Link to post
Share on other sites
I just tried all black and got the same thing. BTW - why would you use black? Wouldnt you need to use black in some images, and not want that to be transparent?

If you can send me your project/game I can test it on this computer and see if it works.

Ratman

Share this post


Link to post
Share on other sites