diff --git a/example-fboTexture/.gitignore b/example-fboTexture/.gitignore new file mode 100644 index 0000000..1af20d0 --- /dev/null +++ b/example-fboTexture/.gitignore @@ -0,0 +1,6 @@ +obj +*.xcodeproj +*.plist +*.xcconfig +*~ +config.make diff --git a/example-fboTexture/Makefile b/example-fboTexture/Makefile new file mode 100644 index 0000000..7a7fe8b --- /dev/null +++ b/example-fboTexture/Makefile @@ -0,0 +1,13 @@ +# Attempt to load a config.make file. +# If none is found, project defaults in config.project.make will be used. +ifneq ($(wildcard config.make),) + include config.make +endif + +# make sure the the OF_ROOT location is defined +ifndef OF_ROOT + OF_ROOT=../../.. +endif + +# call the project makefile! +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk diff --git a/example-fboTexture/addons.make b/example-fboTexture/addons.make new file mode 100644 index 0000000..802cd29 --- /dev/null +++ b/example-fboTexture/addons.make @@ -0,0 +1,3 @@ +ofxPiMapper +ofxUI +ofxXmlSettings diff --git a/example-fboTexture/bin/.gitignore b/example-fboTexture/bin/.gitignore new file mode 100644 index 0000000..44fbbc9 --- /dev/null +++ b/example-fboTexture/bin/.gitignore @@ -0,0 +1,4 @@ +*.app +data/*.jpg +data/settings.xml +data/surfaces.xml diff --git a/example-fboTexture/bin/data/defaultSurfaces.xml b/example-fboTexture/bin/data/defaultSurfaces.xml new file mode 100644 index 0000000..4bcc56a --- /dev/null +++ b/example-fboTexture/bin/data/defaultSurfaces.xml @@ -0,0 +1,138 @@ + + + + + 250.000000000 + 34.000000000 + + + 374.000000000 + 201.000000000 + + + 535.000000000 + 35.000000000 + + + + + 0.101999998 + 0.335999995 + + + 0.328000009 + 0.689999998 + + + 0.705999970 + 0.393999994 + + + + image + image1.jpg + + + + + + 24.396121979 + 259.170288086 + + + 250.000000000 + 34.000000000 + + + 214.630920410 + 282.926849365 + + + + + 0.251666665 + 0.090000004 + + + 0.449999988 + 0.696666658 + + + 0.870000005 + 0.173333332 + + + + image + image5.jpg + + + + + + 75.709846497 + 450.636596680 + + + 214.630920410 + 282.926849365 + + + 24.396121979 + 259.170288086 + + + + + 0.981523871 + 0.471785098 + + + 0.245601788 + 0.110941604 + + + 0.662217021 + 0.714698017 + + + + image + image4.jpg + + + + + + 527.148498535 + 277.815002441 + + + 320.170959473 + 461.102355957 + + + 285.250427246 + 209.424682617 + + + + + 0.031067841 + 0.511202157 + + + 0.450178742 + 0.116164304 + + + 0.543386877 + 0.609848201 + + + + image + none + + + diff --git a/example-fboTexture/bin/data/sources/images/image1.jpg b/example-fboTexture/bin/data/sources/images/image1.jpg new file mode 100644 index 0000000..88cf12e Binary files /dev/null and b/example-fboTexture/bin/data/sources/images/image1.jpg differ diff --git a/example-fboTexture/bin/data/sources/images/image2.jpg b/example-fboTexture/bin/data/sources/images/image2.jpg new file mode 100644 index 0000000..4111693 Binary files /dev/null and b/example-fboTexture/bin/data/sources/images/image2.jpg differ diff --git a/example-fboTexture/bin/data/sources/images/image3.jpg b/example-fboTexture/bin/data/sources/images/image3.jpg new file mode 100644 index 0000000..fffdd35 Binary files /dev/null and b/example-fboTexture/bin/data/sources/images/image3.jpg differ diff --git a/example-fboTexture/bin/data/sources/images/image4.jpg b/example-fboTexture/bin/data/sources/images/image4.jpg new file mode 100644 index 0000000..3291a57 Binary files /dev/null and b/example-fboTexture/bin/data/sources/images/image4.jpg differ diff --git a/example-fboTexture/bin/data/sources/images/image5.jpg b/example-fboTexture/bin/data/sources/images/image5.jpg new file mode 100644 index 0000000..d9f2908 Binary files /dev/null and b/example-fboTexture/bin/data/sources/images/image5.jpg differ diff --git a/example-fboTexture/src/main.cpp b/example-fboTexture/src/main.cpp new file mode 100644 index 0000000..0e0278d --- /dev/null +++ b/example-fboTexture/src/main.cpp @@ -0,0 +1,12 @@ +#include "ofMain.h" +#include "ofApp.h" + +int main() +{ +#ifdef TARGET_RASPBERRY_PI + ofSetupOpenGL(600, 500, OF_FULLSCREEN); +#else + ofSetupOpenGL(600, 500, OF_WINDOW); +#endif + ofRunApp(new ofApp()); +} \ No newline at end of file diff --git a/example-fboTexture/src/ofApp.cpp b/example-fboTexture/src/ofApp.cpp new file mode 100644 index 0000000..8e4895f --- /dev/null +++ b/example-fboTexture/src/ofApp.cpp @@ -0,0 +1,138 @@ +#include "ofApp.h" + +void ofApp::setup() +{ + bShowInfo = false; + + // check if the surfaces.xml file is there + // if not - load defaultSurfaces.xml + if ( ofFile::doesFileExist("surfaces.xml") ) { + surfaceManager.loadXmlSettings("surfaces.xml"); + } else { + surfaceManager.loadXmlSettings("defaultSurfaces.xml"); + } + + // Pass the surface manager to the mapper graphical user interface + gui.setSurfaceManager( &surfaceManager ); + + // Create FBO + fbo = new ofFbo(); + fbo->allocate( 500, 500 ); + setFboAsTexture(); + + // Genereate rects + int numRects = 20; // change this to add more or less rects + for ( int i=0; igetHeight()), fbo->getWidth(), ofRandom(20)) ); + rectSpeeds.push_back( (1.0f + ofRandom(5)) ); + } +} + +void ofApp::update() +{ + // Move rects + for ( int i=0; i fbo->getHeight() ) { + rects[i].y = -rects[i].getHeight(); + } + } + + // Fill FBO + fbo->begin(); + ofClear(0); + ofBackground(0); + ofSetColor(255); + for ( int i=0; iend(); +} + +void ofApp::draw() +{ + // Draw the piMapper GUI + gui.draw(); + + if ( bShowInfo ) { + // Draw instructions + stringstream ss; + ss << "There are 4 modes:\n\n"; + ss << " 1. Presentation mode\n"; + ss << " 2. Texture mapping mode\n"; + ss << " 3. Projection mapping mode\n"; + ss << " 4. Source selection mode\n\n"; + ss << "You can switch between the modes by using <1>, <2>, <3> and <4> keys on the keyboard.\n\n"; + ss << "Press or to add random or normal surface.\n"; + ss << "Press to save the composition.\n"; + ss << "Press to toggle fullscreen.\n"; + ss << "Press to reassign the fbo texture to the first surface\n"; + ss << "Hit to hide this message."; + + ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0,0,0,100), ofColor(255,255,255,200)); + } +} + +void ofApp::exit() +{ + // Clear FBO from mem + delete fbo; +} + +void ofApp::keyPressed(int key) +{ + cout << "Key pressed: " << static_cast(key) << endl; + + switch (key) { + case '1': gui.setMode(ofxGuiMode::NONE); break; + case '2': gui.setMode(ofxGuiMode::TEXTURE_MAPPING); break; + case '3': gui.setMode(ofxGuiMode::PROJECTION_MAPPING); break; + case '4': gui.setMode(ofxGuiMode::SOURCE_SELECTION); break; + case 'i': bShowInfo = !bShowInfo; break; + case 'r': addRandomSurface(); break; + case 'n': addSurface(); break; + case 'f': ofToggleFullscreen(); break; + case 's': surfaceManager.saveXmlSettings("surfaces.xml"); break; + case 'a': setFboAsTexture(); break; + default: break; + } +} + +void ofApp::addRandomSurface() +{ + int surfaceType = ofxSurfaceType::TRIANGLE_SURFACE; + vector vertices; + vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) ); + vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) ); + vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) ); + vector texCoords; + texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) ); + texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) ); + texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) ); + surfaceManager.addSurface(surfaceType, vertices, texCoords); + + // select this surface right away + surfaceManager.selectSurface(surfaceManager.size()-1); +} + +void ofApp::addSurface() +{ + int surfaceType = ofxSurfaceType::TRIANGLE_SURFACE; + vector vertices; + vertices.push_back( ofVec2f( (float)ofGetWidth()/2.0f, 0.0f ) ); + vertices.push_back( ofVec2f( (float)ofGetWidth(), (float)ofGetHeight() ) ); + vertices.push_back( ofVec2f( 0.0f, (float)ofGetHeight() ) ); + vector texCoords; + texCoords.push_back( ofVec2f( 0.5f, 0.0f ) ); + texCoords.push_back( ofVec2f( 1.0f, 1.0f ) ); + texCoords.push_back( ofVec2f( 0.0f, 1.0f ) ); + surfaceManager.addSurface(surfaceType, vertices, texCoords); + + // select this surface right away + surfaceManager.selectSurface(surfaceManager.size()-1); +} + +void ofApp::setFboAsTexture() +{ + surfaceManager.getSurface(0)->setTexture( &fbo->getTextureReference() ); +} \ No newline at end of file diff --git a/example-fboTexture/src/ofApp.h b/example-fboTexture/src/ofApp.h new file mode 100644 index 0000000..39b01f8 --- /dev/null +++ b/example-fboTexture/src/ofApp.h @@ -0,0 +1,30 @@ +#ifndef H_OF_APP +#define H_OF_APP + +#include "ofMain.h" +#include "ofxPiMapper.h" + +class ofApp : public ofBaseApp +{ +public: + void setup(); + void update(); + void draw(); + void exit(); + + void keyPressed(int key); + + void addRandomSurface(); + void addSurface(); + void setFboAsTexture(); + + ofImage image; + ofxSurfaceManager surfaceManager; + ofxSurfaceManagerGui gui; + bool bShowInfo; + ofFbo* fbo; + vector rects; + vector rectSpeeds; +}; + +#endif \ No newline at end of file diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index fc1fc8f..4da0c9c 100644 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -2,7 +2,7 @@ void ofApp::setup() { - image.loadImage("TestPatternInvert.jpg"); + //image.loadImage("TestPatternInvert.jpg"); bShowInfo = false; /* @@ -29,20 +29,6 @@ void ofApp::setup() void ofApp::update() { ofBackground(0); - - ofVec2f p; - p.x = ofRandomWidth(); - p.y = ofRandomHeight(); - //surfaceManager.getSurface(1)->setVertex(0, p); - //triangleSurface.setVertex(0, p); - - ofVec2f t; - t.x = ofRandomuf(); - t.y = ofRandomuf(); - //surfaceManager.getSurface(1)->setTexCoord(0, t); - //triangleSurface.setTexCoord(0, t); - - //surfaceManager.update(); } void ofApp::draw()