Using GL to warp in connection with Alpha mask: no draw

Hi all,

I’m using the incredible ofxBezierWarp to warp my videos. It works perfectly well until I use setAlphaMask() on my fbo. (I got masks to work as well as warping the video. Only using both together stops working and gives me no image at all.)

Setting of mask (works without warping)

        mask.setImageType(OF_IMAGE_COLOR_ALPHA);
        mask.getTexture().setSwizzle(GL_TEXTURE_SWIZZLE_A, GL_RED);
        fbo.getTexture().setAlphaMask(mask.getTexture());

Warping video (works without mask)

    if (bDoWarp) {

        ofTranslate(x, y);
        ofScale(w / fbo.getWidth(), h / fbo.getHeight());

        ofTexture & fboTex = fbo.getTexture();

        // upload the bezier control points to the map surface
        glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, numXPoints, 0, 1, numXPoints * 3, numYPoints, &(cntrlPoints[0]));

        fboTex.bind();

        glMatrixMode(GL_TEXTURE);
        glPushMatrix();
        glLoadIdentity();

        glScalef(fboTex.getWidth(), fboTex.getHeight(), 1.0f);
        glMatrixMode(GL_MODELVIEW);

        glEvalMesh2(GL_FILL, 0, gridDivX, 0, gridDivY);

        fboTex.unbind();

        glMatrixMode(GL_TEXTURE);
        glPopMatrix();
        glMatrixMode(GL_MODELVIEW);

    } else {

        fbo.draw(x, y, w, h);

    }

I also tried using setAlphaMask() on the ofTexture, before I I bind it - same result. I’d prefer to not use multiple fbos (which I did successfully before, but was not very efficient). If someone can help me to get transparency working in the GL stuff, I’d be happy…

thanks and have a great day!
oe

Hi, No idea about that addon’s inner workings. But, would it work if you use another fbo where you “render” image and mask and the do the warping on the fbo?

Hi roymacdonald,

thanks for looking into my question!
to your question: indeed, it would!

I had solved it exactly as you describe in a former version of my project: I prepared an fbo with mask and then “passed it on” to the warp fbo. It worked in the end.
Now I am re-writing my project, trying to improve the code (I will eventually have multiple screens, all warped, so I actually try to avoid the double-fbo-approach - if possible, maybe that’s exaggerated?).
As the warping is GL, it’s sort of over my head what’s happening. But the second code I pasted is indeed the inner magic of the addon, it’s the draw() function…

have a great day!
oe

hi,

not at all. When doing multi pass shaders, for instance, several FBOs are used.
If the fbo approach works I would go for it.
There are probably other parts in your code where you could optimize more.

interesting. :slight_smile:

2 Likes