bitmap: adding alpha channel

hi, i want to load a bitmap and then
add an alpha channel to enable blending later.
heres my code:

timage[0]=auxDIBImageLoad("a.bmp");

isize = timage[0]->sizeX * timage[0]->sizeY; //get size

*timage[1] = (struct _AUX_RGBImageRec*)malloc(sizeof(struct _AUX_RGBImageRec)); //reserver memory
timage[1]->sizeX = timage[0]->sizeX; //copy width and height
timage[1]->sizeY = timage[0]->sizeY;

timage[1]->data = (unsigned char*)malloc((isize + (isize/3))); //reserve memory for data, old size + 1 channel

	for(i=0, h=0 ; i<=isize ; i+=3, h+=4) //loop for copying and adding bytes
	{
	timage[1]->data[h] = timage[0]->data[i];
	timage[1]->data[h+1] = timage[0]->data[i+1];
	timage[1]->data[h+2] = timage[0]->data[i+2];

		if(timage[0]->data[i]==0 && timage[0]->data[i+1]==0 && timage[0]->data[i+2]==255) //if color is blue
		{
		timage[1]->data[h+3] = 0; //set alpha to zero
		}
		else
		{
		timage[1]->data[h+3] = 255;
		}
	}

glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, timage[1]->sizeX, timage[1]->sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, timage[1]->data); //here it crashes :(((

but it crashes at the glTexImage2D call and i dont know why ? if i load the RGB bitmap it works perfectly, where is my mistake ?

Hi,
the third parameter of glTexImage2D has to be 1,2,3 or 4. In your case, try to change it to 4.

that doesnt change anything.
did anybody do this before and could give me his code ?

did it crash without you adding alpha ?

btw the 1,2,3,4 thing is obsolete (still working so), GL since 1.2 allows quite some more internal formats.

yes it does

i think i located the error
isize = timage[0]->sizeX * timage[0]->sizeY * 3;

i forgot the “* 3”, but there are 3 bytes per pixel so its necessary (sorry please dont kill me im new to opengl and programming)

thanks for all who posted