I have a RGB color texture that needs to be masked by a greyscale alpha mask. Ordinarily I would just combine to two textures in a single RGBA texture and call glAlphaFunc( GL_GREATER, 0 ). Unfortunately using a single RGBA is not practical/feasible for what I’m doing.
I cannot use any proprietary OpenGL extensions. Video card is a Geforce MX /w OpenGL v1.2.1.
I have already posted this topic in the Beginners forum with the topic name “Masking” dated 12-07-2000. I have also posted two tries (code) which logically should have worked but failed. To date I have not been unable to solve the problem on my own or based on replied suggestions.
Summary of first posted attempt-
bind the mask as a one component GL_ALPHA texture
bind the color bmp as a 3 component GL_BGR_EXT texture
use a display list to store one GL_QUADS for texture to site on. One glColor4f and 4 glTexCoord & glVertex used.
disable depth testing so mask does not fight with color texture
disable drawing to RGB layers and enable drawing to alpha layer
draw the mask
enable lighting, GL_MODULATE and blending
set glBlendFunc( GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA )
draw color texture
> The idea was to have the mask values drawn into the alpha layer and use the blend function do the masking when the color texture was drawn. Problem was OpenGL drew the alpha value of my quad color (glColor4f) and ignored the alphas in the mask. glColor4f( , alpha) controlled the blending of my entire color texture.
Summary of second posted attempt-
bind the mask as a one component GL_ALPHA texture
bind the color bmp as a 3 component GL_BGR_EXT texture
use a display list to store one GL_QUADS for texture to site on. One glColor4f and 4 glTexCoord & glVertex used.
set default stencil value to zero
clear color and stencil buffer
disable depth testing so mask does not fight with color texture
disable drawing RGBA layers of color buffer
set alpha tests to pass any pixel not black (zero)
set stencil tests to always pass and set to white
draw mask
disable updates to stencil buffer
disable alpha testing
turn on lights, GL_MODULATE
enable writing to RGB layers and disable writing to alpha layer
draw color texture
> The idea here was to use the stencil buffer to store my mask. All non-black alpha pixels would pass the alpha test and go onto become white pixels in the stencil buffer. All black pixels would be discarded by alpha testing thereby leaving their corresponding stencil pixel also black. Again the alphas in my mask were ignored and instead glColor4f( , alpha ) were used. By varing glColor4f( , alpha ) my color texture was completely drawn or not present.
Please help.