Browse Source

Update example, add extra custom source

master
Krisjanis Rijnieks 10 years ago
parent
commit
b2e217bffc
  1. 8
      example/example.xcodeproj/project.pbxproj
  2. 26
      example/src/CrossSource.cpp
  3. 11
      example/src/CrossSource.h
  4. 49
      example/src/CustomSource.cpp
  5. 19
      example/src/CustomSource.h
  6. 27
      example/src/ofApp.cpp
  7. 16
      example/src/ofApp.h

8
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 = "<group>"; };
397EFC801A09047C0009286E /* CustomSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomSource.cpp; sourceTree = "<group>"; };
397EFC811A09047C0009286E /* CustomSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomSource.h; sourceTree = "<group>"; };
399953671BD54FF600D5B1F1 /* CrossSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossSource.cpp; sourceTree = "<group>"; };
399953681BD54FF600D5B1F1 /* CrossSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossSource.h; sourceTree = "<group>"; };
39A867941B0D312400165378 /* SetSourceCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SetSourceCmd.cpp; path = Commands/SetSourceCmd.cpp; sourceTree = "<group>"; };
39A867951B0D312400165378 /* SetSourceCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SetSourceCmd.h; path = Commands/SetSourceCmd.h; sourceTree = "<group>"; };
39A9AADE1B04E78600AA83BC /* RmSurfaceCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RmSurfaceCmd.cpp; path = Commands/RmSurfaceCmd.cpp; sourceTree = "<group>"; };
@ -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 */,

26
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);
}

11
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();
};

49
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]);
}
}

19
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<ofRectangle> rects;
vector<float> 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<ofRectangle> rects;
vector<float> rectSpeeds;
};

27
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 <i> 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 <i> to toggle
// piMapper.showInfo();
}
void ofApp::draw() {
piMapper.draw();
piMapper.draw();
}

16
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;
};
Loading…
Cancel
Save