alpha channel

hi there
i have a .bmp image and i want to add transparency where there is white in the image and this is what i am trying :

unsigned char texturedata = new unsigned char[widthheight*4];

for(int i = 0; i < (widthheight); i++ ) {
texturedata[(4
i)] = bitmapdata[(3i)];//think the problem might be here somewhere but i dunno what
texturedata[(4
i)+1] = bitmapdata[(3i)+1];
texturedata[(4
i)+2] = bitmapdata[(3*i)+2];

if(bitmapdata[(3i)]==255 && bitmapdata[(3i)+1]==255 && bitmapdata[(3i)+2]==255)
texturedata[(4
i)+3] = 0;
else
texturedata[(4*i)+3] = 255;
}

gluBuild2DMipMaps(GL_TEXTURE_2D,4,width,height,GL_BGRA_EXT,GL_UNSIGNED_BYTE,texturedata);

but then when i draw the texture it is sort of on a lean and everything is sorta of smudged sidways can you help me out here thanks

“texture it is sort of on a lean and everything is sorta of smudged sidways” hmmm, I am trying to visualize it ;o)

Anyway, it does sound like you have messed up the width, height or bytes/pixels somewhere, make sure you specify correct width and height in all places, the gluBuild2DMipMaps look’s correct, but are you loading the data correct from the bitmap file ?

If the images is “leaning” it is usualy an indication that the number of bytes per scanline is incorrect, if the bitmap is 3 bytes per pixel, make sure that you don’t need to align the beginning of each scanline on 4 bytes or something like that.

Mikael

[b]

If the images is “leaning” it is usualy an indication that the number of bytes per scanline is incorrect, if the bitmap is 3 bytes per pixel, make sure that you don’t need to align the beginning of each scanline on 4 bytes or something like that.

Mikael[/b]

can you explain this more please i dont quite understand