PDA

View Full Version : alpha channel



jono_123
01-13-2004, 10:46 PM
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[width*height*4];

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

if(bitmapdata[(3*i)]==255 && bitmapdata[(3*i)+1]==255 && bitmapdata[(3*i)+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

mikael_aronsson
01-14-2004, 01:59 AM
"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

jono_123
01-14-2004, 12:02 PM
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

can you explain this more please i dont quite understand