View Full Version : Transparancy on black in BMP

09-13-2006, 05:04 AM
HI, i have made a simple pointsprite/particle program and it works fine, i have made a bmp textuer that has a black background whith a white "ball" on it. You understand, i only want to display the white ball and make the black in the image transparant, to display the other balls behind it correctly, where and how do i set this?

09-13-2006, 05:28 AM
I assume your bitmap is RGB. Do as follows:
-load bitmap
-convert from RGB to RGBA
-send to opengl as texture
Conversion looks like this:
dest.RGB = (255, 255, 255)
dest.A = src.R

So you have white image with ball in alpha channel. Now every time you use this texture enable alpha test:

glAlphaFunc(GL_GREATER, 0.5f);

09-13-2006, 06:00 AM
Can you be a little more specific about this coversion?

09-13-2006, 08:33 AM
Instead of using black RGB image with white ball you use completely white RGBA image with ball in it's alpha channel.
In other words - you want:
RGB = 0, 0, 0 to be invisible
RGB = 255, 255, 255 to be visible
Instead you should use:
RGBA = 255, 255, 255, 0 - invisible white pixel
RGBA = 255, 255, 255, 255 - visible white pixel

All pixels you will draw with such RGBA texture will be white, but alpha test says than only pixels with alpha > 0.5f (>128) are drawn.