Multiple layers and blendmodes

I am working with the addon ofPSBlend which is really fantastic. What I’d like to do, but don’t know how, is to blend more than two images. I’ve been researching and experimenting with open GL, shaders and FBO’s and am getting more confused than anything. I find info on blending two images quite a bit but more than two is something of a brick wall. If anyone can at least point me in the right direction…let me know where to start I’d really appreciate it. Thank you!

My code:


#pragma once

#include "ofMain.h"
#include "ofxPSBlend.h"

class ofApp : public ofBaseApp{

        void setup();
        void update();
        void draw();

        void keyPressed(int key);
        void keyReleased(int key);
        void mouseMoved(int x, int y );
        void mouseDragged(int x, int y, int button);
        void mousePressed(int x, int y, int button);
        void mouseReleased(int x, int y, int button);
        void windowResized(int w, int h);
        void dragEvent(ofDragInfo dragInfo);
        void gotMessage(ofMessage msg);


ofxPSBlend psBlend;
ofImage img1;
ofImage img2;
int blendMode;


#include "ofApp.h"

void ofApp::setup()
    img2.resize(img2.getWidth()/2, img2.getHeight()/2);
    ofSetWindowShape(img2.getWidth(), img2.getHeight());
    img1.crop(img1.getWidth()/2 - img2.getWidth()/2, 0,
              img2.getWidth(), img2.getHeight());
    psBlend.setup(img2.getWidth(), img2.getHeight());
    blendMode = 0;

void ofApp::update()

void ofApp::draw()
    psBlend.draw(img2.getTextureReference(), blendMode = 1);

void ofApp::keyPressed(int key){}
void ofApp::keyReleased(int key){}
void ofApp::mouseMoved(int x, int y){}
void ofApp::mouseDragged(int x, int y, int button){}
void ofApp::mousePressed(int x, int y, int button){}
void ofApp::mouseReleased(int x, int y, int button){}
void ofApp::windowResized(int w, int h){}
void ofApp::gotMessage(ofMessage msg){}
void ofApp::dragEvent(ofDragInfo dragInfo){}

I realize I should clarify further. What I have set up is a base layer and a target layer with a multiply blendmode. I’d like to add another layer with, say, an overlay blendmode.

void ofApp::update()

    psBlend.draw(img2.getTextureReference(), blendMode = 3);


void ofApp::draw()
    psBlend2.draw(img3.getTextureReference(), blendMode = 3);

You have to draw your first render in an other one.


Simple as that. Thank you! I had gotten close to this solution, but didn’t quite get it. I do notice that as I add additional ‘layers’ the image becomes inverted with odd number renders. Nevertheless, this is extremely helpful. Thank you.