implementing image overlay

I have an image which has groups of pixels colored with different RGB values called as segmented image. I have another image texture mapped onto a polygon . Lets call the resulting image as textured image.
Given this, When the user clicks on a particular pixel on the textured image, I pull up an appropriate color group from the segmented image. After this I want to paste all the pixels with the selected group onto the textured image to highlight the selected portion. Thus, basically I want to overlay a part of segmented image onto the textured image and also be able to vary the alpha values of the resulting pixels so that the user can see below the pixel group, into the textured image. I do not want to run through the segmented image to determine all the pixels that belonging to the selected group and then draw them one by one onto the textured image since that will slow down my processing. Is there any faster way to implement this functionality.

Any help is greatly appreciated.



To be honest, I don’t understand half of what you just wrote, but that may just be me.
It sounds to me like you want to paint in layers until you’re ready to merge textures.

I think you may find multitexturing - with the additional texture combiner functionality - useful. The GL_INTERPOLATE mode allows you to overlay one texture with another one using an alphachannel.
You’ll still need to re-upload the highlight texture whenever it changes.

So you want to make “regions” of your texture map selectable and “highlight” the currently selected portion of the texture map?

This should be relatively easy with fragment programs. Just determine the color key of the selection and pass it to the fragment program using a uniform. Then you can write something like (pseudocode):

color = texture2D(image, texcoord);
current_region = texture2D(segmented, texcoord);
if(current_region == selected_region)
    color *= current_region;

Without shaders things will be a little more complicated. For example you could try to use the alpha test with GL_EQUAL. Store the group index in the alpha channel of the segmented image and draw the polygon a second time with alpha test enabled and some blend mode. But this would limit you to 256 segments…