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 ?