Extrange behavior when blitting pixels.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
cederron
Posts: 53
Joined: Thu Jul 13, 2006 11:35 pm

Extrange behavior when blitting pixels.

Post 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??
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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
cederron
Posts: 53
Joined: Thu Jul 13, 2006 11:35 pm

Post 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.
Last edited by cederron on Sat Jan 27, 2007 7:56 pm, edited 1 time in total.
xtheagonyscenex
Posts: 131
Joined: Fri Jun 03, 2005 7:26 pm

Post 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.
"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."
cederron
Posts: 53
Joined: Thu Jul 13, 2006 11:35 pm

Post 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
xtheagonyscenex
Posts: 131
Joined: Fri Jun 03, 2005 7:26 pm

Post by xtheagonyscenex »

sorry i ment to say use a .tga and thought faster than i typed! :lol:
"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."
cederron
Posts: 53
Joined: Thu Jul 13, 2006 11:35 pm

Post 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.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

All routines I just checked do the right thing. Maybe you have a 32bit BMP?
Post Reply