0

I need to merge two images in openGL using an alpha mask.

BUT - I need the alpha mask to apply after the images have been rescaled to the display size - ie. the alpha mask is in screen not image coords.

I thought there was a way of doing a destination alpha buffer in opengl 2.0 but I can't remember the name of it.

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263

1 Answers1

1

You haven't said where exactly this alpha mask comes from or how you generate it. It could be a static alpha mask from a texture or something you build in the framebuffer.

If it comes from a texture, you can do this easily with shaders, or even just texture environment multitexturing. You set the image being "rescaled" as one texture and the alpha mask as the other (as a GL_INTENSITY texture, or GL_RED if you're using core GL 3.1+). Take the RGB from the main texture, but the output alpha should come from your mask texture. Then alpha blend/test/etc as normal.

If the alpha is something you have built into the framebuffer, then it's simply a matter of using the correct blend parameters. There are GL_SRC_* blend parameters, but there are also GL_DST_* blend parameters. You're looking for something based on GL_DST_ALPHA and GL_ONE_MINUS_DST_ALPHA

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • The alpha is a simple odd/even line pattern so it could be a texture (or a shader if I really have to - in that case would just use CUDA). The trick I needed was to do the blend AFTER resizing the image texture – Martin Beckett Sep 06 '11 at 20:27