See through sprites

Started by
6 comments, last by Demirug 18 years, 5 months ago
I am using the directx sprite interface to draw billboards. I want to cause a certain color in the sprite (the background color) to be see through (the term is opaque, I think). How do I do it? Thanks, Asaf Polturak, Israel.
Advertisement
The term you're looking for is "transparent"; "opaque" means "not transparent", so you weren't far off.

What you're describing (using a particular colour for transparency) is known as a "colour key" (or "color key", as it's more likely to be written in the documentation). I suspect that DirectX supports this, but I've always used alpha blending or alpha testing for transparency instead.

Try save your sprite with an alpha channel (you will need something more powerful than MS Paint for this - try GIMP, Photoshop or Paint Shop Pro). Then, when you call ID3DXSprite::Begin remember to pass the D3DXSPRITE_ALPHABLEND flag.

Or wait for someone who known how to do colour keys to reply to this topic. ;)
Quote:Original post by Jaywalk
Or wait for someone who known how to do colour keys to reply to this topic. ;)

You should be able to configure the colour key via D3DXCreateTextureFromFileEx() when you load the texture. That will give you the equivelant of 1-bit alpha. The rest is the same as Jaywalk described...

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

HRESULT D3DXCreateTextureFromFileEx(  LPDIRECT3DDEVICE9 pDevice,  LPCTSTR pSrcFile,  UINT Width,  UINT Height,  UINT MipLevels,  DWORD Usage,  D3DFORMAT Format,  D3DPOOL Pool,  DWORD Filter,  DWORD MipFilter,  D3DCOLOR ColorKey,  D3DXIMAGE_INFO * pSrcInfo,  PALETTEENTRY * pPalette,  LPDIRECT3DTEXTURE9 * ppTexture);


Set the bolded value to a specific color, for example, 0xFF00FF (magenta) or 0xFFFF00FF if you have alpha blending on. :)
I totally agree you should use alpha blending instead of color keying... why use 1-bit alpha when you can use 8-bit alpha? With 1-bit alpha you are going to get jaggies and lower image quality UNLESS your image is only 90 degree angles. Use Photoshop or something and give yourself the power of fades, glows, etc.
im on 1 bit alpha, cause my art program (psp8) doesnt
handle transparency for shit, which is extremely tardy of them.
on the bright side of 1 bit alpha, you get to use D3DFORMAT_DXT1
which compresses for 1 bit alpha especially.
but i dont think youll be able to do very good looking sprite
flares on your lights, but they are too hard to draw anyway. :)
yeh, to set the colour key its just in the texture loader, and use
.pngs if your not using .dds's cause they have no store for alpha
in them, just draw your colour key on it and its fine.
Quote:Original post by MasterWorks
I totally agree you should use alpha blending instead of color keying... why use 1-bit alpha when you can use 8-bit alpha? With 1-bit alpha you are going to get jaggies and lower image quality UNLESS your image is only 90 degree angles. Use Photoshop or something and give yourself the power of fades, glows, etc.


Well, I agree that 1 bit alpha has it's graphical limitations, but it's not a very bad thing to use in certain situations. For instance, if you really only need a single color to be transparent and don't need to do much to it in 2D screen space. You don't notice horrible defects when in 3D space either. I used to use 1 bit color keying before I switched to alpha blending.

Alpha blending is more featured, requires a bit more in terms of texture size, but is a very good system to use.
If you need only full see through I would go for Alphatest instead of Alpha blending as it is normally faster.

This topic is closed to new replies.

Advertisement