diff options
Diffstat (limited to 'glitcher/src')
| -rw-r--r-- | glitcher/src/main.cpp | 2 | ||||
| -rw-r--r-- | glitcher/src/ofApp.cpp | 74 | ||||
| -rw-r--r-- | glitcher/src/ofApp.h | 6 |
3 files changed, 50 insertions, 32 deletions
diff --git a/glitcher/src/main.cpp b/glitcher/src/main.cpp index d134fc9..d77aea4 100644 --- a/glitcher/src/main.cpp +++ b/glitcher/src/main.cpp @@ -1,6 +1,6 @@ #include "ofApp.h" int main() { - ofSetupOpenGL(1024, 768, OF_WINDOW); + ofSetupOpenGL(512,384, OF_WINDOW); ofRunApp(new ofApp()); } diff --git a/glitcher/src/ofApp.cpp b/glitcher/src/ofApp.cpp index 6055485..dee1e2b 100644 --- a/glitcher/src/ofApp.cpp +++ b/glitcher/src/ofApp.cpp @@ -10,6 +10,12 @@ void ofApp::setup() { buffer.allocate(ofGetWidth(),ofGetHeight()); renderFBO.allocate(ofGetWidth(),ofGetHeight(),GL_RGB); //buffer.clear(); + + int bufferSize= ofGetWidth(); //should be based on the size of glitch buffer + + soundStream.listDevices(); + soundStream.setup(this, 0, 2, 44100, bufferSize, 4); + } //-------------------------------------------------------------- @@ -32,44 +38,40 @@ void ofApp::draw() { ofNoFill(); + ofPushMatrix(); ofTranslate(ofGetWidth()/2,ofGetHeight()/2); ofRect(-20,-20,40,40); + ofPopMatrix(); renderFBO.end(); renderFBO.readToPixels(buffer.getPixelsRef()); buffer.flagImageChanged(); - cv::Mat buf = buffer.getCvImage(); - cv::Mat dstbuf; - //create low res remap target - cv::Mat dstX(32,24,CV_32FC1); - cv::Mat dstY(32,24,CV_32FC1); - cv::Mat srcX(32,24,CV_32FC1); - cv::Mat srcY(32,24,CV_32FC1); - - float xFactor=ofGetWidth()/dstX.rows; - float yFactor=ofGetHeight()/dstX.cols; - for (int i=0;i<dstX.cols;i++){ - for (int j=0;j<dstX.rows;j++){ - dstX.at<double>(i,j)=i*xFactor; - dstY.at<double>(i,j)=j*yFactor; + cv::Mat dstX(16,12,CV_32FC1); + cv::Mat dstY(16,12,CV_32FC1); + cv::Mat srcX(16,12,CV_32FC1); + cv::Mat srcY(16,12,CV_32FC1); + + float xFactor=ofGetWidth()/srcX.cols; + float yFactor=ofGetHeight()/srcX.rows; + for (int i=0;i<srcX.cols;i++){ + for (int j=0;j<srcX.rows;j++){ + srcX.at<float>(j,i)=i*xFactor; + srcY.at<float>(j,i)=j*yFactor; } } //transform the low res matrix - float tX=0; //fraction of image - float tY=0; //fraction of image - float oX=0; //fraction of image - float oY=0; //fraction of image + float tX=-.05; //fraction of image + float tY=-.04; //fraction of image + float oX=0.5; //fraction of image + float oY=0.5; //fraction of image float s=0.99; float r=0.0; cv::Point2f srcTri[3], dstTri[3]; - cv::Mat rot_mat(2,3,CV_32FC1); - cv::Mat trans_mat(2,3,CV_32FC1); - cv::Mat out_mat(3,3,CV_32FC1); - + // Compute matrix by creating triangle and transforming srcTri[0].x=0; srcTri[0].y=0; @@ -98,23 +100,33 @@ void ofApp::draw() { dstTri[i].x+=(oX*dstX.cols); dstTri[i].y+=(oY*dstX.cols); } - trans_mat=getAffineTransform( srcTri, dstTri ); - warpAffine( srcX, dstX, trans_mat, srcX.size(), cv::INTER_NEAREST, cv::BORDER_WRAP); - warpAffine( srcY, dstY, trans_mat, srcX.size(), cv::INTER_NEAREST, cv::BORDER_WRAP); + + cv::Mat trans_mat=getAffineTransform(srcTri,dstTri); + warpAffine(srcX,dstX,trans_mat, srcX.size(), cv::INTER_LINEAR, cv::BORDER_WRAP); + warpAffine(srcY,dstY,trans_mat, srcY.size(), cv::INTER_LINEAR, cv::BORDER_WRAP); cv::Mat scaledstX; cv::Mat scaledstY; - cv::resize(dstX,scaledstX, cv::Size(ofGetWidth(),ofGetHeight()), 0, 0, cv::INTER_NEAREST); - cv::resize(dstY,scaledstY, cv::Size(ofGetWidth(),ofGetHeight()), 0, 0, cv::INTER_NEAREST); + cv::resize(dstX,scaledstX, cv::Size(ofGetWidth(),ofGetHeight()), 0, 0, cv::INTER_LINEAR); + cv::resize(dstY,scaledstY, cv::Size(ofGetWidth(),ofGetHeight()), 0, 0, cv::INTER_LINEAR); + + cv::Mat buf = buffer.getCvImage(); + cv::Mat dstbuf; - cv::remap(buf,dstbuf,scaledstX,scaledstY, cv::INTER_LINEAR, cv::BORDER_WRAP, cv::Scalar(0,0, 0) ); - IplImage *tmp = new IplImage(dstbuf); + cv::remap(buf,dstbuf,scaledstX,scaledstY, cv::INTER_NEAREST, cv::BORDER_WRAP); //, cv::Scalar(0,0, 0) ); + tmp = IplImage(dstbuf); - buffer=tmp; - delete tmp; + //buffer=tmp; + //buffer.remap(scaledstX,scaledstY); + buffer=&tmp; renderFBO.draw(0,0); //eventually textured into a viewport + //buffer.draw(0,0); + +} + +void audioIn(float * input, int bufferSize, int nChannels){ } diff --git a/glitcher/src/ofApp.h b/glitcher/src/ofApp.h index fd72e87..c6c831b 100644 --- a/glitcher/src/ofApp.h +++ b/glitcher/src/ofApp.h @@ -18,7 +18,13 @@ public: void mouseReleased(int x, int y, int button); void windowResized(int w, int h); + void audioIn(float * input, int bufferSize, int nChannels); + ofxCvColorImage buffer; ofFbo renderFBO; + IplImage tmp; + + ofSoundStream soundStream; + }; |
