Sign in to follow this  
asafpolt

See through sprites

Recommended Posts

asafpolt    122
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.

Share this post


Link to post
Share on other sites
Jaywalk    250
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. ;)

Share this post


Link to post
Share on other sites
jollyjeffers    1570
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

Share this post


Link to post
Share on other sites
Flimflam    665
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. :)

Share this post


Link to post
Share on other sites
MasterWorks    496
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.

Share this post


Link to post
Share on other sites
rouncer    294
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.

Share this post


Link to post
Share on other sites
Flimflam    665
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this