Page 1 of 1
Extrange behavior when blitting pixels.
Posted: Sat Jan 27, 2007 5:07 pm
by cederron
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??
Posted: Sat Jan 27, 2007 5:28 pm
by vitek
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
Posted: Sat Jan 27, 2007 7:52 pm
by cederron
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 don't know why alpha in the bmp is 0, could be a messed texture??
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.
Posted: Sat Jan 27, 2007 7:55 pm
by xtheagonyscenex
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.
Posted: Sat Jan 27, 2007 8:01 pm
by cederron
xtheagonyscenex 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.
No, BMPs don't have alpha channel, so the alpha value should be 255
but i get value 0 ¿?? that's the problem
Posted: Sat Jan 27, 2007 8:06 pm
by xtheagonyscenex
sorry i ment to say use a .tga and thought faster than i typed!
Posted: Sat Jan 27, 2007 8:35 pm
by cederron
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.
Posted: Sun Jan 28, 2007 3:18 pm
by hybrid
All routines I just checked do the right thing. Maybe you have a 32bit BMP?