   How to use an alpha chanel instead of a color key??
  Hi, I'm trying to learn directx9 programming and I've been following the free parts of the tutorial found at http://www.directxtutorial.com/in the section on making parts of a texture transparent the tutor has only explained how to do so using a set colour that will become transparent as set in...HRESULT D3DXCreateTextureFromFileEx(LPDIRECT3DDEVICE9 pDevice, LPCTSTR pSrcFile, UINT Width, UINT Height, UINT MipLevels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, DWORD Filter, DWORD MipFilter, D3DCOLOR ColorKey,    <- HERE! D3DXIMAGE_INFO* pSrcInfo, PALETTEENTRY* pPalette, LPDIRECT3DTEXTURE9* ppTexture); how can i use the alpha Chanel of a texture instead to have varying levels of transparency?tnx,Leigh   
  I'm not sure, I never used this function before. I guess you need to:a) load a texture that actually contains an alpha channel. Which is not always the case. Watch your file format. PNG, TGA oder DXT may contain alpha channels, BMP or JPG for example can't. b) Specify a D3DFORMAT with an alpha channel. A8R8G8B8 is the usual suspect for this.c) Enable AlphaBlending in the render states. AlphaBlendEnable to true, BlendOp to Add, SrcBlend to SrcAlpha, DstBlend to One_Minus_SrcAlpha. The resulting formula performed by the graphics board is then ResultColor = SourceColor.a * SourceColor + (1 - SourceColor.a) * DestColor . Which in practise works like you'd expect basic alpha blending: the higher your texture's alpha value is, the more of the texture color is visible and the less of the frame's previous pixel is conserved.   ;Quote:Original post by SchrompfWatch your file format. PNG, TGA oder DXT may contain alpha channels, BMP or JPG for example can't. BMP can contain an alpha channel. I don't know whether DX9 will load the alpha channel, as I've never tried to use that format, but BMP definitely can contain one.;  From the Documentation:Quote:ColorKey[in] D3DCOLOR value to replace with transparent black, or 0 to disable the color key. This is always a 32-bit ARGB color, independent of the source image format. Alpha is significant and should usually be set to FF for opaque color keys. Thus, for opaque black, the value would be equal to 0xFF000000.So you just need to set it to 0.When you load a texture with a colour key, you're telling D3DX to set all pixels matching the colour key to zero alpha, and all other pixels to 255 alpha.Also, I'd strongly recommend against that particular website, the tutorials may be easy to follow, but they're also horribly wrong and have all sorts of bugs that will prevent your code from running on a lot of PCs.EDIT:Quote:Original post by sybixsusBMP can contain an alpha channel. I don't know whether DX9 will load the alpha channel, as I've never tried to use that format, but BMP definitely can contain one.Nitpick: You can create a 32-bit BMP, but as far as I'm aware, the format says that the extra 8 bits per pixels are unused, not that they're an alpha channel.   ;Quote:Original post by Evil SteveNitpick: You can create a 32-bit BMP, but as far as I'm aware, the format says that the extra 8 bits per pixels are unused, not that they're an alpha channel.I haven't read the formal documentation for the format, so I can't comment. However, Photoshop loads and saves the alpha channel in BMP's.   ;Quote:Original post by sybixsusQuote:Original post by Evil SteveNitpick: You can create a 32-bit BMP, but as far as I'm aware, the format says that the extra 8 bits per pixels are unused, not that they're an alpha channel.I haven't read the formal documentation for the format, so I can't comment. However, Photoshop loads and saves the alpha channel in BMP's.If the format doesn't specify that the extra padding is or can be used as an alpha channel, then the use of the extra channel to store alpha is not portable. Photoshop may take advantage of it, but other programs handling bitmaps according to the format specification may not.   ;Quote:Original post by Brother BobIf the format doesn't specify that the extra padding is or can be used as an alpha channel, then the use of the extra channel to store alpha is not portable. Photoshop may take advantage of it, but other programs handling bitmaps according to the format specification may not.Quite true, of course, but that wasn't the question, nor did I claim it otherwise. The comment was that the format "can't" contain an alpha channel, and my reply was that it "can". As far as it being portable, I explicitly stated that DX9 might not load it.   ;Quote:Original post by sybixsusQuote:Original post by Brother BobIf the format doesn't specify that the extra padding is or can be used as an alpha channel, then the use of the extra channel to store alpha is not portable. Photoshop may take advantage of it, but other programs handling bitmaps according to the format specification may not.Quite true, of course, but that wasn't the question, nor did I claim it otherwise. The comment was that the format "can't" contain an alpha channel, and my reply was that it "can". As far as it being portable, I explicitly stated that DX9 might not load it.You claimed that Photoshop can use the the padding for alpha channel, to which I responded that it is purely their choice to do so, outside the support of the BMP format specification. The format does not give you the option to store an alpha channel. A particular program may chose to store the alpha channel in the unused part of the file.   ;Ok thanks, so basicaly i dont use a colour key, i just enable alpha blending and the alpha chanel i make in photoshop should work, cool.Quote:Original post by Evil SteveAlso, I'd strongly recommend against that particular website, the tutorials may be easy to follow, but they're also horribly wrong and have all sorts of bugs that will prevent your code from running on a lot of PCs.can you suggest a better one? i dont really know where to look but so far this has been the only thing that has enabled me to get into some practical work with directx programming that hasnt thrown me in the deep end where i have no idea which way is up.   ;Quote:Original post by Jackson311can you suggest a better one? i dont really know where to look but so far this has been the only thing that has enabled me to get into some practical work with directx programming that hasnt thrown me in the deep end where i have no idea which way is up.Recent thread on the For Beginners forum.   