Jump to content
  • Advertisement

Archived

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

Possibility

Colorkeying in D3D

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

Hi, I have a Direct3D program and its working fine and everything, but I have some images (texture) where I want portions of it transparent, so I was using colorkeying, inparticular I was using the pure green color for the colorkey, but when the textures appear they have a bright green ring around them, where the green color was blended with the surrounding color and was no longer pure green and was thus not made transparent, so how do I fix this and get rid of that green edge around my textures? Possibility

Share this post


Link to post
Share on other sites
Advertisement
Hehe, I have absolutely not a clue what that means Serge, but I have heard of alpha blending which is one of the reasons I am getting into directx, all I have managed to put in so far is the 3D, the 3 kinds of light sources, some simple objects like cubes and to apply textures to them, i guess I will eventually get to alpha blending but I was looking now was just colorkeying out an area of an image(texture) to make it totaly transparent.

Possibility

Share this post


Link to post
Share on other sites
First post:
Are you sure the edges are pure green?
It may be fault of your bitmap loading routines if you are stretching your images.

Second/third post:
You should stray away from colorkeys in D3D because not all cards support that type of transparency, whereas almost all cards support alpha bitmodes.

the alpha value is basically the value of a texture''s opaqueness/translucency.

What serge meant, is that if you''re using 16-bit modes, try and create a texture where 1 bit is for alpha, 5 for red, green and blue respectively.

To get texture formats with Alpha values you need to enumerate the surface formats (read up if you don''t know) and select one with an alpha value. Then you need to change your bitmap loading routines to check for your transparent color and if so, set the pixel of the texture to have an alpha of total transparency.

I would go through these steps before continuing because you will need them if you ever plan to do anything fun with d3d

Share this post


Link to post
Share on other sites
quote:
Original post by Possibility

..but I was looking now was just colorkeying out an area of an image(texture) to make it totaly transparent.



You can do it with alpha test.

pD3DDev->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, TRUE );
pD3DDev->SetRenderState( D3DRENDERSTATE_ALPHAFUNC, D3DCMP_GREATEREQUAL );
pD3DDev->SetRenderState( D3DRENDERSTATE_ALPHAREF, 255 );

Share this post


Link to post
Share on other sites
Almost all cards support colorkeying, except my virge. And according to my experiments somewhat faster than alpha channel. You should set:

d3dDevice->SetRenderState( D3DRENDERSTATE_COLORKEYENABLE, TRUE );

Look for the following routine in the SDK to find out how to set a texture''s colorkey property.

HRESULT DDSetColorKey( LPDIRECTDRAWSURFACE4 pdds, COLORREF rgb );

( I would have been glad for this answer 2 years ago. )


bernie
www.bkgames.com

Share this post


Link to post
Share on other sites
ok, what I did was is exactly like bernatk said. What I have for example is a square image, in that image i painted a image, like a red circle, and surroundin that red circle i laid pure green down to fill in the corners of the square image, and I then colorkeyed out that area. Now when I put that image as a texture on a surface, it does in deed make the green transparent so I cant see it, except on the edge of the circle, where the green blends with the red, so the red circle has a ''kind of'' greenish ring around it, but I will indeed look into that alpha stuff, it sounds cool.

Possibility

Share this post


Link to post
Share on other sites
quote:
Original post by bernatk
Almost all cards support colorkeying, except my virge.



Now I know of two cards that don''t support colorkeying, the aforesaid and my diamond card, yet I still don''t know of any which doesn''t support alpha texture formats. I would say that more support is for alpha textures than to color keying (all of the sdk examples use alpha, except one specific color keying example, which might be an indication too).

Share this post


Link to post
Share on other sites
quote:
Original post by Possibility

ok, what I did was is exactly like bernatk said. What I have for example is a square image, in that image i painted a image, like a red circle, and surroundin that red circle i laid pure green down to fill in the corners of the square image, and I then colorkeyed out that area. Now when I put that image as a texture on a surface, it does in deed make the green transparent so I cant see it, except on the edge of the circle, where the green blends with the red, so the red circle has a ''kind of'' greenish ring around it, but I will indeed look into that alpha stuff, it sounds cool.

Possibility


If you have green blended with red around the edges of the circle, then you should have some greenish red pixels right? and color keying makes either a yes/no to every pixel based on it''s color and if the pixel isn''t exactly the color you specified then well, it''s shown.

Share this post


Link to post
Share on other sites
Yah, but there are no blended pixels in the image, just open up MS Paint, make an image 64x64 pixels, use the fill and fill in pure green, and select the filled-circle and select the red color and place a circle in the middle of the image, thats all I have done. So I know it is actually D3D that is doing the blending of the green-red on the edge of the circle, so there is a small fading, if I put the image on a texture on a zoom way in close to it, you can see it go from what appears to be near pure green to pure red, and that I dont understand why its doing that, its like its doing anti-aliasing on the image ''before'' its removing the colorkey color, and that is just confusing me cause i never even turned on anti-aliasing.

Possibility

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!