I'm trying to create a custom made cursor in one of my programs and I want the black pixels around the cursor to be transparent. I am using glut for my graphics system and I don't want to use the blending function "glBlendFunc(GL_SRC_ALPHA, GL_ONE)" because it doesn't quite get the effect i want.

What I am really looking for is a loading function that will add an alpha value to the loaded image depending on what color the pixel is. The folowing is the current code I am using to load my images.

thx alot, that worked like a charm, but I realized I still have to use blending functions and I can't find the right functions to use to make it so just the areas with 0 alpha value are transparent and the rest doesn't blend. I changed int a = .3*r + .59*g + .11*b; to if(r = 0 && b == 0....) then a = 0. and the rest of the cursor still gets blended and I can't see any of it on white. I'm using glBlendFunc(...); but I can't find what I should use in the parenthesis.

Hlz

09-09-2005, 12:32 PM

If you use glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPA), then you get an equation that amounts to texAlpha * texColor + (1 - texAlpha) * frameBufferColor (provided you set glColor3f(1,1,1) with modulate texenv mode). So if you want your cursor to be opaque where it's not black and transparent where it is black, you need if( r|g|b ) a = 255; else a = 0; That way with normalized alpha = 1 you get all texture; at alpha = 0 you get all framebuffer.

You may also want to enable the alpha test with glAlphaFunc(GL_GREATER,0). This can save on fill if the texture is mostly transparent. For a single small cursor image, it's not a big deal. but it's a handy optimization to keep in mind for alpha blending vacuous textures.