Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Moving my alpha mask?

$
0
0

@Caroline_Record wrote:

I am using .setAlphaMask() and .setAnchorPoint(0,0) to dynamically move a series of masks around. I cannot get the masks to budge unless I redraw the fbo in each frame, which I rather not do for performance reasons.

First in set up I am making my various masks using a shader called "gradientMaker" and storing all of textures in a vector called "theMasks".

    // this bit is just how I am making mask, which isn't impt to the question.
    int interval = width/(allDayImage.size()*2);
    int imgWidth = allDayImage.at(0).getWidth();
    int imgHeight = allDayImage.at(0).getHeight();
    for (int i=0; i < allDayImage.size(); i++){
        ofFbo mask;
        mask.allocate(imgWidth, imgHeight);
        mask.begin();
            ofClear(0, 0, 0, 0);
            gradientMaker.begin();
                gradientMaker.setUniform1i("startFade",posMsk + interval*i);
                gradientMaker.setUniform1i("center", posMsk + width/2);
                gradientMaker.setUniform1i("endFade",posMsk +  width - interval*i );
                ofDrawRectangle(0, 0,imgWidth,imgHeight);
            gradientMaker.end();
        mask.end();

        //this is where I add the mask to the vector, which might be important.
        ofTexture temp = mask.getTexture();
        temp.setAnchorPoint(mskPos, 0);
        theMasks.push_back(temp);

    }

Then in update I assign the masks to their respective images and attempt to move their position forward.

mskPos++;
for (int i=0; i < allDayImages.size(); i++){
        theMasks.at(i).setAnchorPoint(mskPos, 0);
        allDayImages.at(i).getTexture().setAlphaMask(theMasks.at(i));
        allDayImages.at(i).update();
 }

When I draw the images the masks are applied, but not moving like I intended:

for (int i = 3; i < allDayImage.size(); i++){
        allDayImages.at(i).draw(0,0);
}

BUT when I actually draw one of the masks it is moving after all! But that is somehow not being reflected when it is applied as an alpha mask to the image.

theMasks.at(0).draw(0,0);

Any suggestions? I am confused because I know I am successfully getting the mask and moving its position because I see that when I draw just the mask. And I know that I can use image.setAlphaMask(texture) and image.update() to change the texture in update because I've done that when I've used a video as an alpha mask. So what factor am I not considering?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles