From b2e217bffc9fd14e9b60f641da98f1c7362f7ffb Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Mon, 19 Oct 2015 19:22:30 +0200 Subject: [PATCH] Update example, add extra custom source --- example/example.xcodeproj/project.pbxproj | 8 +++- example/src/CrossSource.cpp | 26 ++++++++++++ example/src/CrossSource.h | 11 +++++ example/src/CustomSource.cpp | 49 +++++++++++------------ example/src/CustomSource.h | 19 ++++----- example/src/ofApp.cpp | 27 +++++++------ example/src/ofApp.h | 16 ++++---- 7 files changed, 102 insertions(+), 54 deletions(-) create mode 100644 example/src/CrossSource.cpp create mode 100644 example/src/CrossSource.h diff --git a/example/example.xcodeproj/project.pbxproj b/example/example.xcodeproj/project.pbxproj index 88927fc..0ea6332 100644 --- a/example/example.xcodeproj/project.pbxproj +++ b/example/example.xcodeproj/project.pbxproj @@ -32,6 +32,7 @@ 397EFC7C1A08E7680009286E /* ofxPiMapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 397EFC7B1A08E7680009286E /* ofxPiMapper.cpp */; }; 397EFC7F1A08FE720009286E /* FboSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 397EFC7D1A08FE720009286E /* FboSource.cpp */; }; 397EFC821A09047C0009286E /* CustomSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 397EFC801A09047C0009286E /* CustomSource.cpp */; }; + 399953691BD54FF600D5B1F1 /* CrossSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 399953671BD54FF600D5B1F1 /* CrossSource.cpp */; }; 39A867961B0D312400165378 /* SetSourceCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A867941B0D312400165378 /* SetSourceCmd.cpp */; }; 39A9AAE01B04E78600AA83BC /* RmSurfaceCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AADE1B04E78600AA83BC /* RmSurfaceCmd.cpp */; }; 39A9AAE91B0518FC00AA83BC /* MvSurfaceCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AAE71B0518FC00AA83BC /* MvSurfaceCmd.cpp */; }; @@ -180,6 +181,8 @@ 397EFC7E1A08FE720009286E /* FboSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FboSource.h; sourceTree = ""; }; 397EFC801A09047C0009286E /* CustomSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomSource.cpp; sourceTree = ""; }; 397EFC811A09047C0009286E /* CustomSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomSource.h; sourceTree = ""; }; + 399953671BD54FF600D5B1F1 /* CrossSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossSource.cpp; sourceTree = ""; }; + 399953681BD54FF600D5B1F1 /* CrossSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossSource.h; sourceTree = ""; }; 39A867941B0D312400165378 /* SetSourceCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SetSourceCmd.cpp; path = Commands/SetSourceCmd.cpp; sourceTree = ""; }; 39A867951B0D312400165378 /* SetSourceCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SetSourceCmd.h; path = Commands/SetSourceCmd.h; sourceTree = ""; }; 39A9AADE1B04E78600AA83BC /* RmSurfaceCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RmSurfaceCmd.cpp; path = Commands/RmSurfaceCmd.cpp; sourceTree = ""; }; @@ -802,8 +805,10 @@ E4B69E1D0A3A1BDC003C02F2 /* main.cpp */, E4B69E1E0A3A1BDC003C02F2 /* ofApp.cpp */, E4B69E1F0A3A1BDC003C02F2 /* ofApp.h */, - 397EFC801A09047C0009286E /* CustomSource.cpp */, 397EFC811A09047C0009286E /* CustomSource.h */, + 397EFC801A09047C0009286E /* CustomSource.cpp */, + 399953681BD54FF600D5B1F1 /* CrossSource.h */, + 399953671BD54FF600D5B1F1 /* CrossSource.cpp */, ); path = src; sourceTree = SOURCE_ROOT; @@ -952,6 +957,7 @@ 391717F31B0A8A7300F9A484 /* MvAllTexCoordsCmd.cpp in Sources */, 397EFC7C1A08E7680009286E /* ofxPiMapper.cpp in Sources */, 39C1244219EE9589005DF557 /* HiddenFileFilter.cpp in Sources */, + 399953691BD54FF600D5B1F1 /* CrossSource.cpp in Sources */, 39C1244819EE9589005DF557 /* SearchPath.cpp in Sources */, 39C1248019F187D5005DF557 /* SourcesEditor.cpp in Sources */, 391717EF1B08FFDA00F9A484 /* SetApplicationStateCmd.cpp in Sources */, diff --git a/example/src/CrossSource.cpp b/example/src/CrossSource.cpp new file mode 100644 index 0000000..6516c79 --- /dev/null +++ b/example/src/CrossSource.cpp @@ -0,0 +1,26 @@ +#include "CrossSource.h" + +CrossSource::CrossSource() { + name = "Cross FBO Source"; + allocate(500, 500); +} + +void CrossSource::draw() { + ofClear(0); + ofSetColor(255, 255, 0, 255); + ofRect(0, 0, getWidth(), getHeight()); + + ofSetColor(0, 0, 0, 255); + ofSetLineWidth(5); + + float y = sin( float(ofGetFrameNum()) / 10.0f ) * 100.0f; + + ofPoint startPoint = ofPoint(10, y); + ofPoint endPoint = ofPoint(getWidth() - 10, getHeight() - y); + ofLine(startPoint, endPoint); + + float tempY = startPoint.y; + startPoint.y = endPoint.y; + endPoint.y = tempY; + ofLine(startPoint, endPoint); +} \ No newline at end of file diff --git a/example/src/CrossSource.h b/example/src/CrossSource.h new file mode 100644 index 0000000..985aa9b --- /dev/null +++ b/example/src/CrossSource.h @@ -0,0 +1,11 @@ +#pragma once + +#include "ofMain.h" +#include "FboSource.h" + +class CrossSource : public ofx::piMapper::FboSource { + public: + CrossSource(); + + void draw(); +}; \ No newline at end of file diff --git a/example/src/CustomSource.cpp b/example/src/CustomSource.cpp index 08d0f9a..dd9c260 100644 --- a/example/src/CustomSource.cpp +++ b/example/src/CustomSource.cpp @@ -1,43 +1,42 @@ #include "CustomSource.h" -// Don't do any drawing here -void CustomSource::setup() { - // Give our source a decent name - name = "Custom FBO Source"; +CustomSource::CustomSource() { + // Give our source a decent name + name = "Custom FBO Source"; - // Allocate our FBO source, decide how big it should be - allocate(500, 500); + // Allocate our FBO source, decide how big it should be + allocate(500, 500); - // Genereate rects to be rendered into the FBO - int numRects = 20; // change this to add more or less rects - for (int i = 0; i < numRects; i++) { - rects.push_back(ofRectangle(0, + // Genereate rects to be rendered into the FBO + int numRects = 20; // change this to add more or less rects + for (int i = 0; i < numRects; i++) { + rects.push_back(ofRectangle(0, ofRandom(fbo->getHeight()), fbo->getWidth(), ofRandom(20))); - rectSpeeds.push_back((1.0f + ofRandom(5))); - } + rectSpeeds.push_back((1.0f + ofRandom(5))); + } } // Don't do any drawing here void CustomSource::update() { - // Move rects - for (int i = 0; i < rects.size(); i++) { - rects[i].y += rectSpeeds[i]; - if (rects[i].y > fbo->getHeight()) { - rects[i].y = -rects[i].getHeight(); + // Move rects + for (int i = 0; i < rects.size(); i++) { + rects[i].y += rectSpeeds[i]; + if (rects[i].y > fbo->getHeight()) { + rects[i].y = -rects[i].getHeight(); + } } - } } // No need to take care of fbo.begin() and fbo.end() here. // All within draw() is being rendered into fbo; void CustomSource::draw() { - // Fill FBO with our rects - ofClear(0); - //ofBackground(0); - ofSetColor(255); - for (int i = 0; i < rects.size(); i++) { - ofRect(rects[i]); - } + // Fill FBO with our rects + ofClear(0); + //ofBackground(0); + ofSetColor(255); + for (int i = 0; i < rects.size(); i++) { + ofRect(rects[i]); + } } \ No newline at end of file diff --git a/example/src/CustomSource.h b/example/src/CustomSource.h index 5993d80..bddb984 100644 --- a/example/src/CustomSource.h +++ b/example/src/CustomSource.h @@ -4,14 +4,15 @@ #include "FboSource.h" class CustomSource : public ofx::piMapper::FboSource { -public: - // These are overrides of FboSource virtual functions. - // FBO sources are not executing before they have been assigned to a surface. - void setup(); - void update(); - void draw(); // You don't have to care about fbo.begin() or fbo.end() here + public: + CustomSource(); -private: - vector rects; - vector rectSpeeds; + // These are overrides of FboSource virtual functions. + // FBO sources are not executing before they have been assigned to a surface. + void update(); + void draw(); // You don't have to care about fbo.begin() or fbo.end() here + + private: + vector rects; + vector rectSpeeds; }; \ No newline at end of file diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index 45d6c8a..455331b 100755 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -1,19 +1,22 @@ #include "ofApp.h" void ofApp::setup() { - ofBackground(0); - - // Add our CustomSource to list of fbo sources of the piMapper - // FBO sources should be added before piMapper.setup() so the - // piMapper is able to load the source if it is assigned to - // a surface in XML settings. - piMapper.addFboSource(customSource); - piMapper.setup(); - - // The info layer is hidden by default, press to toggle - // piMapper.showInfo(); + ofBackground(0); + + // Add our CustomSource to list of fbo sources of the piMapper + // FBO sources should be added before piMapper.setup() so the + // piMapper is able to load the source if it is assigned to + // a surface in XML settings. + crossSource = new CrossSource(); + customSource = new CustomSource(); + piMapper.addFboSource(*crossSource); + piMapper.addFboSource(*customSource); + piMapper.setup(); + + // The info layer is hidden by default, press to toggle + // piMapper.showInfo(); } void ofApp::draw() { - piMapper.draw(); + piMapper.draw(); } \ No newline at end of file diff --git a/example/src/ofApp.h b/example/src/ofApp.h index 008239f..be19ff2 100755 --- a/example/src/ofApp.h +++ b/example/src/ofApp.h @@ -3,15 +3,17 @@ #include "ofMain.h" #include "ofxPiMapper.h" #include "CustomSource.h" +#include "CrossSource.h" class ofApp : public ofBaseApp { -public: - void setup(); - void draw(); + public: + void setup(); + void draw(); - ofxPiMapper piMapper; + ofxPiMapper piMapper; - // By using a custom source that is derived from FboSource - // you will be able to see the source listed in sources editor - CustomSource customSource; + // By using a custom source that is derived from FboSource + // you will be able to see the source listed in sources editor + CustomSource * customSource; + CrossSource * crossSource; }; \ No newline at end of file