Hello,
I have a scene node with EMT_TRANSPARENT_ALPHA_CHANNEL_REF flag enabled and it has a .tga texture with an alpha channel.
Now I'm copying some pixels from a .bmp file, bmp has no alpha channel, then the pixels copied should be fully opaque, right? Wrong! when displayed are fully transparent. I have checked with the debugger and the alpha value of the bmp pixels is 0, so the pixels copied should be opaque.
I have to get every pixel alpha and set a value of 255 then they are opaque. But this shouldn't really be done.
I thought 0 was opaque and 255 transparent??
Extrange behavior when blitting pixels.
vitek wrote:No, alpha 0 is transparent and 255 is opaque. I don't know how you are copying pixels from the .bmp file, but the most common color bitmaps are 24-bit BGR. So you would have to be getting the alpha component from somewhere when you are copying pixels in.
Travis
I load the bmp in an irrlicht texture with getTexture(), getColorFormat returns A8R8G8B8
then I blit like this (I have irrlicht textures wrapped) :
Code: Select all
//SOURCE TEXTURE IS THE BMP FILE, AND DEST IS A TGA WITH ALPHA CHANNEL
//get pointers to buffers
unsigned int *psrcbegin = (unsigned int*)pSourceTex->LockBuffer();
unsigned int *pdestbegin = (unsigned int*)pDestTex->LockBuffer();
unsigned int *pSrc = NULL;
unsigned int *pDest = NULL;
pSrc = psrcbegin + (srcY1 * sourceWidth) + srcX1;
pDest = pdestbegin + (destY1 * destWidth) + destX1;
//blit
for(int i = 0; i < rectheight; i++ )
{
for(int j = 0; j < rectwidth; j++)
{
int alpha = (pSrc[j]>>24) & 0xff; // IN HERE ALPHA IS 0, RED IS FINE I THINK
int red = (pSrc[j]>>16) & 0xff;
if(pSrc[j] != MaskColor)
{
pDest[j] = pSrc[j];
pDest[j] = ((255 & 0xff)<<24) | (pDest[j] & 0x00ffffff); // I HAVE TO SET ALPHA TO 255
}
}
pSrc += sourceWidth;
pDest += destWidth;
}
pSourceTex->UnlockBuffer();
pDestTex->UnlockBuffer();
I have been playing with it in photoshop, however it looks fine in most applications.
Also I'm using irrlicht 1.1 but i think it makes no difference.
Last edited by cederron on Sat Jan 27, 2007 7:56 pm, edited 1 time in total.
-
- Posts: 131
- Joined: Fri Jun 03, 2005 7:26 pm
theres another flag you can use with a regular alpha channel(no _REF_) as long as the backround is transparent i think for the REF to work the bmp's background has to be black.
"Held in Your arms but too far from my heart." "These thoughts will carry me through the darkest nights...while your eyes rest in mine."
"How quickly I forget that this is meaningless."
"How quickly I forget that this is meaningless."
No, BMPs don't have alpha channel, so the alpha value should be 255xtheagonyscenex wrote:theres another flag you can use with a regular alpha channel(no _REF_) as long as the backround is transparent i think for the REF to work the bmp's background has to be black.
but i get value 0 ¿?? that's the problem
-
- Posts: 131
- Joined: Fri Jun 03, 2005 7:26 pm
I remember I had some trouble to get a tga, and had to use a bmp. The file was generated by a bitmap font generator and I had to do several conversions to make it work.
Well if there's not another solution i will have to mess again and try to get a tga.
Would be nice to get the bmp loaded correctly though.
Well if there's not another solution i will have to mess again and try to get a tga.
Would be nice to get the bmp loaded correctly though.