Blend Mode help

Hi, Is there a blend mode where when you draw, it only replaces places that have 0 alpha, and doesn’t draw on places where the pixel to draw on already has alpha?

Thanks,
roland

glBlendFunc works using two values: the source color and the destination color. You are allowed to multiply these two values with glBlendFunc using the two arguments. For example, if you want standard blending, you’d write

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

meaning

result = sourceColor * sourceAlpha + destinationColor * (1-sourceAlpha);

If alpha is 1, destColor is multiplied by 0, and if alpha is 0.5, the source color and the destination color are mixed equally.

What do you want? You want to multiply the source color with the destination alpha, right?

glBlendFunc(GL_DST_ALPHA, GL_ZERO); //Assuming you want to discard the destination color and alpha

meaning

result = sourceColor * destinationAlpha + destinationColor * 0

which can be simplified to

result = sourceColor * destinationAlpha

Your post says you want to discard any pixel that has any alpha at all. You cannot achieve this with exact effect with blending, but the above blend function is very similar and what I think you want. You can however do exactly what you asked about with the stencil test. Instead of writing whether a pixel should be “drawable” or not to the alpha channel, you would mark the pixel with a specific value and then disable rendering to pixels with that specific value using the stencil test.

Thanks so much theagentd! :slight_smile: It turns out I did need GL_ONE_MINUS_SRC_ALPHA, and something else in my program was causing a bug that thought I needed something else. Thanks for the extra information though, I understand blend modes a lot better now ;D

No problem! ;D