D3D8, Sprites, and Color Keying

Started by
10 comments, last by Ratman 22 years, 9 months ago
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
Advertisement
Hmm, try the example .exe and code posted here:

http://home.att.net/~rpgbook/Transblt.zip

Jim
If you still get the black border, then try enabling alpha testing.

Jim
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.
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

  Downloads:  ZeroOne Realm

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?
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...
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
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
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com
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.
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

This topic is closed to new replies.

Advertisement