PDA

View Full Version : Blending a simple pic



La_Onda
01-10-2002, 04:44 AM
I would like to now how i can blend my pic so that the black on my pic won't be visable.

My problem: I would like to make a tree, i have a nice pic for it. But the outside of the pic is black. I also have a mask of the pic. I would like to know how i can easily get rid of the black in my pic? I seen it done in projects with blending and i just would like to know how this is done. In simple explanation :-)

Rob The Bloke
01-10-2002, 05:28 AM
Use an alpha channel on the image to act as a mask. Load the image as a 32bit RGBA image and enable bledining as follows:

glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
// draw polygon with texture applied here
glDisable(GL_BLEND);

La_Onda
01-10-2002, 06:56 AM
Well i see that i was missing RGBA in my texture load, but when i add the line:"look GL_RGBA"

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8 , image1->sizeX, image1->sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, image1->data);

in stead of:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8 , image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);

i am getting a unhandeld exception access violation.So there is another problem :-(

Bob
01-10-2002, 10:04 AM
He meant that you should conver the image data from RGB to RGBA (after you loaded it from file, but before uploaded to OpenGL), copying each RGB value from the old image to the new image, and fill the alpha channel with one or zero, depending on if the color of the pixel is black or not.

The upload it like this: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ..., GL_RGBA, UNSIGNED_BYTE, newData);

La_Onda
01-10-2002, 10:22 AM
Oke tnx guys i got it working, not very nice for now. But it will do. Tnx very much!