What is the simplest way to use ofCircle, ofRectangle etc as mask for underlying ofImage.
I can see how to do with an ofMesh, but I would like to benefit from the simplicity of 2D drawing with ofGraphics (there is no simple “draw circle” function in ofMesh).
I usually do this via a shader, you can create an FBO which is the same size as the image, then draw into it what you want to pass through, then use a shader to use the color of one texture as the alpha of the pictures color.
there are also tricks to do this with color masking in opengl –
this (almost a decade) old thread might have some info:
also in 0.9.0 you can set an alpha mask texture to another texture like:
ofTexture tex, mask;
tex.allocate(w,h,GL_RGBA);
mask.allocate(w,h,GL_LUMINANCE); // or GL_RED in opengl 3+
tex.setAlphaMask(mask);
when drawing tex it’ll me be masked by mask using the values in the mask as alpha values. so you can use an ofFbo allocated with GL_LUMINANCE (or GL_RED), draw into it and set it’s texture as mask of another texture