Hello, I am using ofxPSBlend that is developed by @Akira_At_Asia for my leap motion project. ofxPSBlend functions like layers in PS, where one could add opacity to the image/video they draw whilst layering each other~
I have trouble with disabling the blendMode in one of the condition. I have tried a lot of ways, even trying to address it as psBlend.draw(videos[++currentVideo].getTextureReference(), 0);
, I have even tried closing webcam with webcam.close();
but that would result in closing the webcam totally.
What I wanted to do is to disable the webcam layering on top of the demoVideo when it is in drawState2
You may find my code below:
.h:
#pragma once
#include "ofMain.h"
#include "ofxPSBlend.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
bool stateOne = false;
bool stateTwo = false;
ofVideoPlayer videos[3];
int currentVideo = 0;
ofVideoGrabber webcam;
ofxPSBlend psBlend;
int blendMode;
int drawState = 0; // 0->drawstate1 | 1-> drawstate2 | 2->drawstate3
.cpp:
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofSetFrameRate(60);
ofSetVerticalSync(true);
ofSetLogLevel(OF_LOG_VERBOSE);
leap.open();
webcam.setDeviceID(0);
webcam.setVerbose(true);
webcam.initGrabber(1280, 720);
videos[0].loadMovie("holdBrush1.m4v"); //LoopVideo1
videos[1].loadMovie("holdBrush2.m4v"); //LoopVideo2
videos[2].loadMovie("dotsdotsdots.m4v"); //demoVideo
currentVideo = 0;
videos[0].play();
videos[0].setLoopState(OF_LOOP_NORMAL);
videos[1].setLoopState(OF_LOOP_NORMAL);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
/*
psBlend.setup(videos[0].getWidth(), videos[0].getHeight());
psBlend.setup(videos[1].getWidth(), videos[1].getHeight());
*/
psBlend.setup(videos[currentVideo].getWidth(), videos[currentVideo].getHeight());
blendMode = 11;
}
//--------------------------------------------------------------
void ofApp::update(){
webcam.update();
psBlend.begin();
cout << "drawWebcam" << endl;
ofPushMatrix();
ofTranslate(1024,0);
ofScale(-1,1);
ofSetColor(255);
webcam.draw(0,0);
ofPopMatrix();
psBlend.end();
/* some code here for updating fingers positions from leap motion that would determine if fingers are in certain range that defines states*/
stateOne = inRange0 && inRange1 && inRange2;
stateTwo = stateOne && inRange4 && inRange3;
if (drawState == 0){ //play LoopVideo1
cout << "drawState1, play LoopVideo1" << endl;
if (stateOne){
drawState = 1;
videos[currentVideo].stop(); //stop videos.[0]
psBlend.draw(videos[++currentVideo].getTextureReference(), blendMode);
cout << "drawState2, play LoopVideo2" << endl;
videos[++currentVideo].play(); //++ adds up the value of the video previously by 1
}
} else if (drawState == 1){ //play LoopVideo2
if(stateTwo){
drawState = 2;
videos[currentVideo].stop(); //stop videos.[1]
cout << "drawState3, play DemoVideo" << endl;
// psBlend.draw(videos[++currentVideo].getTextureReference(), 0);
videos[++currentVideo].play();
}
} else if (drawState == 2){ //play DemoVideo
if( videos[currentVideo].getCurrentFrame() == videos[currentVideo].getTotalNumFrames()){
videos[currentVideo].stop(); //stop videos.[2]
currentVideo = 0;
psBlend.draw(videos[currentVideo].getTextureReference(), blendMode);
videos[currentVideo].play();
drawState = 0;
inRange0 = inRange1 = inRange2 = inRange3 = inRange4 = false;
}
}
videos[currentVideo].update();
leap.markFrameAsOld();
}
//--------------------------------------------------------------
void ofApp::draw(){
psBlend.draw(videos[currentVideo].getTextureReference(), blendMode);
/*
psBlend.draw(videos[0].getTextureReference(), blendMode);
psBlend.draw(videos[1].getTextureReference(), blendMode);
*/
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if (key == OF_KEY_UP){
if (blendMode >= 24){
blendMode = 0;
} else {
blendMode++;
}
}
if (key == OF_KEY_DOWN){
if (blendMode <= 0){
blendMode = 24;
} else {
blendMode--;
}
}
}
Thanks a lot and have a lovely day!
Cheers,
Karen