d3dx colorkey problems

Started by
4 comments, last by +AA_970+ 23 years, 12 months ago
Hi, i tried drawing a sprite with a colorkey (bright pink (255,0,255)) in d3dx, but there is an outline (the same color as the colorkey) around the sprite. Is there a way to get around this, and is there another (better) way to achieve the results of colorkeying? I''ve read that there is a way to do colorkeying with alpha blending can someone explain how this is done. +AA_970+
Advertisement
If you are using colorkeying then there is no way of getting rid of the outline. You can try to minimize the effect by using a colorkey as close to the background as possible. But it will still be there. (Note: The outline might not be visible on some cards, it depends on how colorkeying is treated in the card)

And yes there is a better way to achieve the results of colorkeying. And that is to use alpha blending (as you already knew). To do this your sprite image must be created with an alpha channel where the alpha is set to zero for the parts that should be transparent, and 255 for the opaque parts. Then you need to enable alpha blending which is done by making these calls

pD3DDev->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
pD3DDev->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
pD3DDev->SetRenderState(D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCALPHA);

By the way the color (255,0,255) is purple not pink. Pink would be something like (255,128,128).

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

What software can i use to add an alpha channel to my sprites?

Also, i want my game to use both d3dx for users with 3d cards and direct draw (with Blt, BltFast, & Pixel Plots) for users without 3d cards. Will adding an alpha channel affect the sprite in direct draw mode?

Another Question , Is the alpha channel saved as part of the image along with the RGB values?



+AA_970+
I''m pretty sure photoshop can save alpha channels for certain types of 32bit images. Though I''m not sure if it would be hard or not to read.

For supporting both users, you must do just that. Write two different loading and color keying functions depending on which rendering method they use.

Again, see note about photoshop. It will save alpha channels, but probably in their own format only. I''m not sure what other graphics format supports alpha channels and has an editing program to go with. Some people choose to make a regular bitmap, then have a separate bitmap and have it in only black and white. It would just be the alpha channel (this, in theory, wouldn''t take up much more space than having an all-in-one format) so you might want to look into doing something like that.

quote:Original post by +AA_970+

What software can i use to add an alpha channel to my sprites?

Also, i want my game to use both d3dx for users with 3d cards and direct draw (with Blt, BltFast, & Pixel Plots) for users without 3d cards. Will adding an alpha channel affect the sprite in direct draw mode?

Another Question , Is the alpha channel saved as part of the image along with the RGB values?



+AA_970+


___________________________Freeware development:ruinedsoft.com
Photoshop can save 32 bit TGA images which are easily loaded. D3DX even has a function that can do it: D3DXCreateTextureFromFile().

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks Alot for the help guys!

+AA_970+

This topic is closed to new replies.

Advertisement