Changing fbo opacity while using ofxPiMapper


#1

Haven’t been able to find a way to change the opacity of my fbo sources while using ofxPiMapper. Anyone know how I should go about doing this? I’m looking to overlay/blend certain fbo sources with other fbo sources.

//fbo source

#include "Overlay1.hpp"
void Overlay1::setup() {
    name = "Overlay1";
    allocate(400, 400);
    ofEnableAlphaBlending();
}

void Overlay1::update() {
}

void Overlay1::draw() {
    ofClear(0,0,0,0);
    ofBackground(0, 0, 0, 0);
    ofSetColor(255, 255, 255, 50);
    ofDrawRectangle(0, 0, 100, 100);
}
#include "ofApp.h"

void ofApp::setup(){
	ofBackground(0,0,0,0);
    ofSetFrameRate(60);
    ofEnableAlphaBlending();
	ofx::piMapper::VideoSource::enableAudio = true;
	ofx::piMapper::VideoSource::useHDMIForAudio = false;

    movingRectSource = new MovingRectSource();
    movingRectSource->setup();
    piMapper.registerFboSource(movingRectSource);
	
    overlay1 = new Overlay1();
    overlay1->setup();
    piMapper.registerFboSource(overlay1);
    piMapper.setup();
	
	ofSetFullscreen(Settings::instance()->getFullscreen());
	ofSetEscapeQuitsApp(false);
    dummyObjects.load("nestedRendered.png");
    sceneManager.setup("scenes.json", &piMapper);
}
void ofApp::update(){
	piMapper.update();
    sceneManager.update();
}
void ofApp::draw(){
    dummyObjects.draw(100,100);
    piMapper.draw();
}

#2

hi. can you post the your code please?


#3

Sure thing. Not much to show–I’ve been trying everything I can to affect the opacity within the fbo source and within ofxPiMapper itself. I’m a bit new to oF so my approach might be way off.
(edit: moved code to original comment)


#4

here’s how I typically do it

fbo.begin();
        ofClear(0, 0, 0, 0);
        ofEnableBlendMode(OF_BLENDMODE_ALPHA);
        ofSetColor(255, 255, 255, displayAlpha);
        texture.draw(0, 0);
        ofDisableBlendMode();
fbo.end();

#5

Figured it out:

Go into addons/ofxPiMapper/src/Surfaces/SurfaceStack.cpp
In SurfaceStack::draw(), add ofEnableAlphaBlending() to the if statement inside the for loop
right under all the glblend stuff.

void SurfaceStack::draw(){
	for(int i = 0; i < _surfaces.size(); ++i){
		if(_surfaces[i]->getSource()->getType() == SourceType::SOURCE_TYPE_FBO){
			glEnable(GL_BLEND); 
			glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
            ofEnableAlphaBlending(); //<-- here
		}else{
			ofEnableAlphaBlending();
		}
		_surfaces[i]->draw();
	}
}