25 changed files with 2177 additions and 356 deletions
@ -1,6 +1,5 @@ |
|||||
obj |
obj |
||||
*.xcodeproj |
*.xcworkspace |
||||
*.plist |
*.xcuserdatad |
||||
*.xcconfig |
|
||||
*~ |
*~ |
||||
config.make |
config.make |
||||
|
@ -0,0 +1,17 @@ |
|||||
|
//THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT. |
||||
|
//THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED |
||||
|
OF_PATH = ../../.. |
||||
|
|
||||
|
//THIS HAS ALL THE HEADER AND LIBS FOR OF CORE |
||||
|
#include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig" |
||||
|
|
||||
|
//ICONS - NEW IN 0072 |
||||
|
ICON_NAME_DEBUG = icon-debug.icns |
||||
|
ICON_NAME_RELEASE = icon.icns |
||||
|
ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/ |
||||
|
|
||||
|
//IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to: |
||||
|
//ICON_FILE_PATH = bin/data/ |
||||
|
|
||||
|
OTHER_LDFLAGS = $(OF_CORE_LIBS) |
||||
|
HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS) |
File diff suppressed because it is too large
@ -0,0 +1,86 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<Scheme |
||||
|
LastUpgradeVersion = "0460" |
||||
|
version = "1.3"> |
||||
|
<BuildAction |
||||
|
parallelizeBuildables = "YES" |
||||
|
buildImplicitDependencies = "YES"> |
||||
|
<BuildActionEntries> |
||||
|
<BuildActionEntry |
||||
|
buildForTesting = "YES" |
||||
|
buildForRunning = "YES" |
||||
|
buildForProfiling = "YES" |
||||
|
buildForArchiving = "YES" |
||||
|
buildForAnalyzing = "YES"> |
||||
|
<BuildableReference |
||||
|
BuildableIdentifier = "primary" |
||||
|
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
||||
|
BuildableName = "example.app" |
||||
|
BlueprintName = "example" |
||||
|
ReferencedContainer = "container:example.xcodeproj"> |
||||
|
</BuildableReference> |
||||
|
</BuildActionEntry> |
||||
|
</BuildActionEntries> |
||||
|
</BuildAction> |
||||
|
<TestAction |
||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" |
||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" |
||||
|
shouldUseLaunchSchemeArgsEnv = "YES" |
||||
|
buildConfiguration = "Debug"> |
||||
|
<Testables> |
||||
|
</Testables> |
||||
|
<MacroExpansion> |
||||
|
<BuildableReference |
||||
|
BuildableIdentifier = "primary" |
||||
|
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
||||
|
BuildableName = "example.app" |
||||
|
BlueprintName = "example" |
||||
|
ReferencedContainer = "container:example.xcodeproj"> |
||||
|
</BuildableReference> |
||||
|
</MacroExpansion> |
||||
|
</TestAction> |
||||
|
<LaunchAction |
||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" |
||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" |
||||
|
launchStyle = "0" |
||||
|
useCustomWorkingDirectory = "NO" |
||||
|
buildConfiguration = "Debug" |
||||
|
ignoresPersistentStateOnLaunch = "NO" |
||||
|
debugDocumentVersioning = "YES" |
||||
|
allowLocationSimulation = "YES"> |
||||
|
<BuildableProductRunnable> |
||||
|
<BuildableReference |
||||
|
BuildableIdentifier = "primary" |
||||
|
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
||||
|
BuildableName = "example.app" |
||||
|
BlueprintName = "example" |
||||
|
ReferencedContainer = "container:example.xcodeproj"> |
||||
|
</BuildableReference> |
||||
|
</BuildableProductRunnable> |
||||
|
<AdditionalOptions> |
||||
|
</AdditionalOptions> |
||||
|
</LaunchAction> |
||||
|
<ProfileAction |
||||
|
shouldUseLaunchSchemeArgsEnv = "YES" |
||||
|
savedToolIdentifier = "" |
||||
|
useCustomWorkingDirectory = "NO" |
||||
|
buildConfiguration = "Debug" |
||||
|
debugDocumentVersioning = "YES"> |
||||
|
<BuildableProductRunnable> |
||||
|
<BuildableReference |
||||
|
BuildableIdentifier = "primary" |
||||
|
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
||||
|
BuildableName = "example.app" |
||||
|
BlueprintName = "example" |
||||
|
ReferencedContainer = "container:example.xcodeproj"> |
||||
|
</BuildableReference> |
||||
|
</BuildableProductRunnable> |
||||
|
</ProfileAction> |
||||
|
<AnalyzeAction |
||||
|
buildConfiguration = "Debug"> |
||||
|
</AnalyzeAction> |
||||
|
<ArchiveAction |
||||
|
buildConfiguration = "Debug" |
||||
|
revealArchiveInOrganizer = "YES"> |
||||
|
</ArchiveAction> |
||||
|
</Scheme> |
@ -0,0 +1,86 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<Scheme |
||||
|
LastUpgradeVersion = "0460" |
||||
|
version = "1.3"> |
||||
|
<BuildAction |
||||
|
parallelizeBuildables = "YES" |
||||
|
buildImplicitDependencies = "YES"> |
||||
|
<BuildActionEntries> |
||||
|
<BuildActionEntry |
||||
|
buildForTesting = "YES" |
||||
|
buildForRunning = "YES" |
||||
|
buildForProfiling = "YES" |
||||
|
buildForArchiving = "YES" |
||||
|
buildForAnalyzing = "YES"> |
||||
|
<BuildableReference |
||||
|
BuildableIdentifier = "primary" |
||||
|
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
||||
|
BuildableName = "example.app" |
||||
|
BlueprintName = "example" |
||||
|
ReferencedContainer = "container:example.xcodeproj"> |
||||
|
</BuildableReference> |
||||
|
</BuildActionEntry> |
||||
|
</BuildActionEntries> |
||||
|
</BuildAction> |
||||
|
<TestAction |
||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" |
||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" |
||||
|
shouldUseLaunchSchemeArgsEnv = "YES" |
||||
|
buildConfiguration = "Release"> |
||||
|
<Testables> |
||||
|
</Testables> |
||||
|
<MacroExpansion> |
||||
|
<BuildableReference |
||||
|
BuildableIdentifier = "primary" |
||||
|
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
||||
|
BuildableName = "example.app" |
||||
|
BlueprintName = "example" |
||||
|
ReferencedContainer = "container:example.xcodeproj"> |
||||
|
</BuildableReference> |
||||
|
</MacroExpansion> |
||||
|
</TestAction> |
||||
|
<LaunchAction |
||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" |
||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" |
||||
|
launchStyle = "0" |
||||
|
useCustomWorkingDirectory = "NO" |
||||
|
buildConfiguration = "Release" |
||||
|
ignoresPersistentStateOnLaunch = "NO" |
||||
|
debugDocumentVersioning = "YES" |
||||
|
allowLocationSimulation = "YES"> |
||||
|
<BuildableProductRunnable> |
||||
|
<BuildableReference |
||||
|
BuildableIdentifier = "primary" |
||||
|
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
||||
|
BuildableName = "example.app" |
||||
|
BlueprintName = "example" |
||||
|
ReferencedContainer = "container:example.xcodeproj"> |
||||
|
</BuildableReference> |
||||
|
</BuildableProductRunnable> |
||||
|
<AdditionalOptions> |
||||
|
</AdditionalOptions> |
||||
|
</LaunchAction> |
||||
|
<ProfileAction |
||||
|
shouldUseLaunchSchemeArgsEnv = "YES" |
||||
|
savedToolIdentifier = "" |
||||
|
useCustomWorkingDirectory = "NO" |
||||
|
buildConfiguration = "Release" |
||||
|
debugDocumentVersioning = "YES"> |
||||
|
<BuildableProductRunnable> |
||||
|
<BuildableReference |
||||
|
BuildableIdentifier = "primary" |
||||
|
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2" |
||||
|
BuildableName = "example.app" |
||||
|
BlueprintName = "example" |
||||
|
ReferencedContainer = "container:example.xcodeproj"> |
||||
|
</BuildableReference> |
||||
|
</BuildableProductRunnable> |
||||
|
</ProfileAction> |
||||
|
<AnalyzeAction |
||||
|
buildConfiguration = "Release"> |
||||
|
</AnalyzeAction> |
||||
|
<ArchiveAction |
||||
|
buildConfiguration = "Release" |
||||
|
revealArchiveInOrganizer = "YES"> |
||||
|
</ArchiveAction> |
||||
|
</Scheme> |
@ -0,0 +1,22 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
||||
|
<plist version="1.0"> |
||||
|
<dict> |
||||
|
<key>CFBundleDevelopmentRegion</key> |
||||
|
<string>English</string> |
||||
|
<key>CFBundleExecutable</key> |
||||
|
<string>${EXECUTABLE_NAME}</string> |
||||
|
<key>CFBundleIdentifier</key> |
||||
|
<string>cc.openFrameworks.ofapp</string> |
||||
|
<key>CFBundleInfoDictionaryVersion</key> |
||||
|
<string>6.0</string> |
||||
|
<key>CFBundlePackageType</key> |
||||
|
<string>APPL</string> |
||||
|
<key>CFBundleSignature</key> |
||||
|
<string>????</string> |
||||
|
<key>CFBundleVersion</key> |
||||
|
<string>1.0</string> |
||||
|
<key>CFBundleIconFile</key> |
||||
|
<string>${ICON}</string> |
||||
|
</dict> |
||||
|
</plist> |
@ -0,0 +1,43 @@ |
|||||
|
#include "CustomSource.h" |
||||
|
|
||||
|
// Don't do any drawing here
|
||||
|
void CustomSource::setup() { |
||||
|
// Give our source a decent name
|
||||
|
name = "Custom FBO Source"; |
||||
|
|
||||
|
// 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, |
||||
|
ofRandom(fbo->getHeight()), |
||||
|
fbo->getWidth(), |
||||
|
ofRandom(20))); |
||||
|
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(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 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]); |
||||
|
} |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "ofMain.h" |
||||
|
#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
|
||||
|
|
||||
|
private: |
||||
|
vector<ofRectangle> rects; |
||||
|
vector<float> rectSpeeds; |
||||
|
}; |
@ -1,12 +1,34 @@ |
|||||
#include "ofMain.h" |
#include "ofMain.h" |
||||
#include "ofApp.h" |
#include "ofApp.h" |
||||
|
#include <string> |
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
#ifdef TARGET_RASPBERRY_PI |
#ifdef TARGET_RASPBERRY_PI |
||||
ofSetupOpenGL(600, 500, OF_FULLSCREEN); |
// Accept arguments in the Pi version
|
||||
|
int main(int argc, char* argv[]) { |
||||
|
|
||||
|
bool fullscreen = false; |
||||
|
|
||||
|
if (argc > 0) { |
||||
|
std::string fullscreenFlag = "-f"; |
||||
|
for (int i = 0; i < argc; i++) { |
||||
|
if (strcmp(argv[i], fullscreenFlag.c_str()) == 0) { |
||||
|
fullscreen = true; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (fullscreen) { |
||||
|
ofSetupOpenGL(600, 500, OF_FULLSCREEN); |
||||
|
} else { |
||||
|
ofSetupOpenGL(800, 450, OF_WINDOW); |
||||
|
} |
||||
|
|
||||
|
ofRunApp(new ofApp()); |
||||
|
} |
||||
#else |
#else |
||||
ofSetupOpenGL(600, 500, OF_WINDOW); |
int main() { |
||||
|
ofSetupOpenGL(800, 600, OF_WINDOW); |
||||
|
ofRunApp(new ofApp()); |
||||
|
} |
||||
#endif |
#endif |
||||
ofRunApp(new ofApp()); |
|
||||
} |
|
@ -1,190 +1,19 @@ |
|||||
#include "ofApp.h" |
#include "ofApp.h" |
||||
|
|
||||
void ofApp::setup() { |
void ofApp::setup() { |
||||
bShowInfo = false; |
|
||||
|
|
||||
// Pass pointers to our media server instance to both:
|
|
||||
// surface manager and it's gui, only then we will be able to
|
|
||||
// load surface data from xml settings files
|
|
||||
surfaceManager.setMediaServer(&mediaServer); |
|
||||
gui.setMediaServer(&mediaServer); |
|
||||
|
|
||||
// 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); |
|
||||
fboSource = new ofx::piMapper::BaseSource(&fbo->getTextureReference()); |
|
||||
setFboAsSource(); |
|
||||
|
|
||||
// Genereate rects
|
|
||||
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))); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
void ofApp::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(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// Fill FBO
|
|
||||
fbo->begin(); |
|
||||
ofClear(0); |
|
||||
ofBackground(0); |
ofBackground(0); |
||||
ofSetColor(255); |
|
||||
for (int i = 0; i < rects.size(); i++) { |
// Add our CustomSource to list of fbo sources of the piMapper
|
||||
ofRect(rects[i]); |
// FBO sources should be added before piMapper.setup() so the
|
||||
} |
// piMapper is able to load the source if it is assigned to
|
||||
fbo->end(); |
// a surface in XML settings.
|
||||
|
piMapper.addFboSource(customSource); |
||||
|
piMapper.setup(); |
||||
|
|
||||
|
// The info layer is hidden by default, press <i> to toggle
|
||||
|
// piMapper.showInfo();
|
||||
} |
} |
||||
|
|
||||
void ofApp::draw() { |
void ofApp::draw() { |
||||
// Draw the piMapper GUI
|
piMapper.draw(); |
||||
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 <r> or <n> to add random or normal surface.\n"; |
|
||||
ss << "Press <q> to add a new quad surface.\n"; |
|
||||
ss << "Press <s> to save the composition.\n"; |
|
||||
ss << "Press <f> to toggle fullscreen.\n"; |
|
||||
ss << "Press <a> to reassign the fbo texture to the first surface\n"; |
|
||||
ss << "Hit <i> 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<char>(key) << endl; |
|
||||
|
|
||||
switch (key) { |
|
||||
case '1': |
|
||||
gui.setMode(ofx::piMapper::GuiMode::NONE); |
|
||||
break; |
|
||||
case '2': |
|
||||
gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING); |
|
||||
break; |
|
||||
case '3': |
|
||||
gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING); |
|
||||
break; |
|
||||
case '4': |
|
||||
gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION); |
|
||||
break; |
|
||||
case 'i': |
|
||||
bShowInfo = !bShowInfo; |
|
||||
break; |
|
||||
case 'r': |
|
||||
addRandomSurface(); |
|
||||
break; |
|
||||
case 'q': |
|
||||
addQuadSurface(); |
|
||||
break; |
|
||||
case 'n': |
|
||||
addSurface(); |
|
||||
break; |
|
||||
case 'f': |
|
||||
ofToggleFullscreen(); |
|
||||
break; |
|
||||
case 's': |
|
||||
surfaceManager.saveXmlSettings("surfaces.xml"); |
|
||||
break; |
|
||||
case 'a': |
|
||||
setFboAsSource(); |
|
||||
break; |
|
||||
case OF_KEY_BACKSPACE: |
|
||||
surfaceManager.removeSelectedSurface(); |
|
||||
break; |
|
||||
default: |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
void ofApp::addRandomSurface() { |
|
||||
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; |
|
||||
vector<ofVec2f> vertices; |
|
||||
vertices.push_back(ofVec2f(ofRandomWidth(), ofRandomHeight())); |
|
||||
vertices.push_back(ofVec2f(ofRandomWidth(), ofRandomHeight())); |
|
||||
vertices.push_back(ofVec2f(ofRandomWidth(), ofRandomHeight())); |
|
||||
vector<ofVec2f> 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::addQuadSurface() { |
|
||||
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; |
|
||||
vector<ofVec2f> vertices; |
|
||||
|
|
||||
int border = 50; |
|
||||
vertices.push_back(ofVec2f(border, border)); |
|
||||
vertices.push_back(ofVec2f(ofGetWidth() - border, border)); |
|
||||
vertices.push_back(ofVec2f(ofGetWidth() - border, ofGetHeight() - border)); |
|
||||
vertices.push_back(ofVec2f(border, ofGetHeight() - border)); |
|
||||
|
|
||||
vector<ofVec2f> texCoords; |
|
||||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f))); |
|
||||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f))); |
|
||||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f))); |
|
||||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f))); |
|
||||
|
|
||||
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
|
||||
|
|
||||
// select this surface right away
|
|
||||
surfaceManager.selectSurface(surfaceManager.size() - 1); |
|
||||
} |
|
||||
|
|
||||
void ofApp::addSurface() { |
|
||||
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; |
|
||||
vector<ofVec2f> 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<ofVec2f> 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::setFboAsSource() { |
|
||||
surfaceManager.getSurface(0)->setSource(fboSource); |
|
||||
} |
} |
@ -0,0 +1,81 @@ |
|||||
|
#include "FboSource.h" |
||||
|
|
||||
|
namespace ofx { |
||||
|
namespace piMapper { |
||||
|
FboSource::FboSource() : fbo(NULL) { |
||||
|
name = PIMAPPER_DEF_FBO_SOURCE_NAME; |
||||
|
loadable = false; |
||||
|
loaded = false; |
||||
|
type = SourceType::SOURCE_TYPE_FBO; |
||||
|
ofAddListener(ofEvents().setup, this, &FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); |
||||
|
} |
||||
|
|
||||
|
FboSource::~FboSource() { |
||||
|
removeAppListeners(); |
||||
|
clear(); |
||||
|
} |
||||
|
|
||||
|
void FboSource::addAppListeners() { |
||||
|
ofLogNotice("FboSource") << "Adding app listeners"; |
||||
|
ofAddListener(ofEvents().update, this, &FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); |
||||
|
ofAddListener(ofEvents().draw, this, &FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); |
||||
|
ofAddListener(ofEvents().exit, this, &FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); |
||||
|
} |
||||
|
|
||||
|
void FboSource::removeAppListeners() { |
||||
|
ofLogNotice("FboSource") << "Removing app listeners"; |
||||
|
ofRemoveListener(ofEvents().update, this, &FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); |
||||
|
ofRemoveListener(ofEvents().draw, this, &FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); |
||||
|
ofRemoveListener(ofEvents().exit, this, &FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); |
||||
|
} |
||||
|
|
||||
|
void FboSource::onAppSetup(ofEventArgs &args) { |
||||
|
ofRemoveListener(ofEvents().setup, this, &FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); |
||||
|
setup(); |
||||
|
} |
||||
|
|
||||
|
void FboSource::onAppUpdate(ofEventArgs &args) { |
||||
|
if (fbo == NULL || !fbo->isAllocated()) { |
||||
|
ofLogWarning("FboSource") << "FBO not allocated"; |
||||
|
return; |
||||
|
} |
||||
|
update(); |
||||
|
} |
||||
|
|
||||
|
void FboSource::onAppDraw(ofEventArgs &args) { |
||||
|
if (fbo == NULL || !fbo->isAllocated()) { |
||||
|
ofLogWarning("FboSource") << "FBO not allocated"; |
||||
|
return; |
||||
|
} |
||||
|
fbo->begin(); |
||||
|
draw(); |
||||
|
fbo->end(); |
||||
|
} |
||||
|
|
||||
|
void FboSource::onAppExit(ofEventArgs &args) { |
||||
|
exit(); |
||||
|
} |
||||
|
|
||||
|
void FboSource::allocate(int width, int height) { |
||||
|
clear(); |
||||
|
fbo = new ofFbo(); |
||||
|
fbo->allocate(width, height); |
||||
|
|
||||
|
// Clear FBO
|
||||
|
fbo->begin(); |
||||
|
ofClear(0); |
||||
|
fbo->end(); |
||||
|
|
||||
|
texture = &(fbo->getTextureReference()); |
||||
|
} |
||||
|
|
||||
|
void FboSource::clear() { |
||||
|
texture = NULL; |
||||
|
if (fbo != NULL) { |
||||
|
delete fbo; |
||||
|
fbo = NULL; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
@ -0,0 +1,49 @@ |
|||||
|
/*
|
||||
|
Use this as base class for your generative sources: |
||||
|
|
||||
|
class YourGenerativeSource : public FboSource { |
||||
|
// Your code here
|
||||
|
} |
||||
|
*/ |
||||
|
#pragma once |
||||
|
|
||||
|
#include "ofMain.h" |
||||
|
#include "BaseSource.h" |
||||
|
|
||||
|
#define PIMAPPER_DEF_FBO_SOURCE_NAME "FBO Source" |
||||
|
|
||||
|
namespace ofx { |
||||
|
namespace piMapper { |
||||
|
class FboSource : public BaseSource { |
||||
|
public: |
||||
|
FboSource(); |
||||
|
~FboSource(); |
||||
|
|
||||
|
// Add/remove calls to update and draw
|
||||
|
// App listeners are added once the source is assigned to at least one surface
|
||||
|
// App listeners are removed once the source is not assigned anywhere
|
||||
|
void addAppListeners(); |
||||
|
void removeAppListeners(); |
||||
|
|
||||
|
// These are called on app events
|
||||
|
void onAppSetup(ofEventArgs& args); |
||||
|
void onAppUpdate(ofEventArgs& args); |
||||
|
void onAppDraw(ofEventArgs& args); |
||||
|
void onAppExit(ofEventArgs& args); |
||||
|
|
||||
|
// Override these in your custom FBO source
|
||||
|
virtual void setup() {}; // Don't do any drawing here
|
||||
|
virtual void update() {}; // Don't do any drawing here
|
||||
|
// You don't need to take care of fbo.begin() and fbo.end() here;
|
||||
|
virtual void draw() {}; // But this is the only place where you shoud do drawing
|
||||
|
virtual void exit() {}; |
||||
|
|
||||
|
// Use these to set up FBo itself
|
||||
|
void allocate(int width, int height); |
||||
|
void clear(); // The only method from BaseSource to be overriden
|
||||
|
|
||||
|
protected: |
||||
|
ofFbo* fbo; |
||||
|
}; |
||||
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
@ -0,0 +1,160 @@ |
|||||
|
#include "ofxPiMapper.h" |
||||
|
|
||||
|
ofxPiMapper::ofxPiMapper(): |
||||
|
bShowInfo(false), |
||||
|
isSetUp(false){ |
||||
|
ofAddListener(ofEvents().keyPressed, this, &ofxPiMapper::keyPressed); |
||||
|
} |
||||
|
|
||||
|
ofxPiMapper::~ofxPiMapper() { |
||||
|
ofRemoveListener(ofEvents().keyPressed, this, &ofxPiMapper::keyPressed); |
||||
|
} |
||||
|
|
||||
|
void ofxPiMapper::setup() { |
||||
|
ofLogNotice("ofxPiMapper") << "Setting up..."; |
||||
|
|
||||
|
// Assign media server to other pi mapper components
|
||||
|
surfaceManager.setMediaServer(&mediaServer); |
||||
|
gui.setMediaServer(&mediaServer); |
||||
|
|
||||
|
// Check if we have user surfaces defined, if not - load default
|
||||
|
if (ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)) { |
||||
|
ofLogNotice("ofxPiMapper") << "Loading user surfaces from " << PIMAPPER_USER_SURFACES_XML_FILE; |
||||
|
surfaceManager.loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE); |
||||
|
} else { |
||||
|
ofLogNotice("ofxPiMapper") << "Loading default surfaces from " << PIMAPPER_DEF_SURFACES_XML_FILE; |
||||
|
surfaceManager.loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE); |
||||
|
} |
||||
|
|
||||
|
// The GUI needs something to interface with
|
||||
|
gui.setSurfaceManager(&surfaceManager); |
||||
|
|
||||
|
isSetUp = true; |
||||
|
|
||||
|
ofLogNotice("ofxPiMapper") << "Done setting up"; |
||||
|
} |
||||
|
|
||||
|
void ofxPiMapper::draw() { |
||||
|
if (!isSetUp) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
// 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 <t> to add new triangle surface\n"; |
||||
|
ss << "Press <q> to add new quad surface\n"; |
||||
|
ss << "Press <s> to save the composition\n"; |
||||
|
ss << "Press <f> to toggle fullscreen\n"; |
||||
|
ss << "Press <i> to hide this message"; |
||||
|
|
||||
|
ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0, 0, 0, 100), |
||||
|
ofColor(255, 255, 255, 200)); |
||||
|
} |
||||
|
|
||||
|
} // draw
|
||||
|
|
||||
|
void ofxPiMapper::keyPressed(ofKeyEventArgs &args) { |
||||
|
ofLogNotice("ofxPiMapper") << "Key pressed: " << static_cast<char>(args.key); |
||||
|
|
||||
|
switch (args.key) { |
||||
|
case '1': |
||||
|
gui.setMode(ofx::piMapper::GuiMode::NONE); |
||||
|
break; |
||||
|
case '2': |
||||
|
gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING); |
||||
|
break; |
||||
|
case '3': |
||||
|
gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING); |
||||
|
break; |
||||
|
case '4': |
||||
|
gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION); |
||||
|
break; |
||||
|
case 'i': |
||||
|
bShowInfo = !bShowInfo; |
||||
|
break; |
||||
|
case 'q': |
||||
|
addQuadSurface(); |
||||
|
break; |
||||
|
case 't': |
||||
|
addTriangleSurface(); |
||||
|
break; |
||||
|
case 'f': |
||||
|
ofToggleFullscreen(); |
||||
|
break; |
||||
|
case 's': |
||||
|
surfaceManager.saveXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE); |
||||
|
break; |
||||
|
case OF_KEY_BACKSPACE: |
||||
|
surfaceManager.removeSelectedSurface(); |
||||
|
break; |
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
} // keyPressed
|
||||
|
|
||||
|
void ofxPiMapper::addFboSource(ofx::piMapper::FboSource &fboSource) { |
||||
|
mediaServer.addFboSource(fboSource); |
||||
|
} // addFboSource
|
||||
|
|
||||
|
void ofxPiMapper::addTriangleSurface() { |
||||
|
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; |
||||
|
|
||||
|
vector<ofVec2f> vertices; |
||||
|
float margin = 50.0f; |
||||
|
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin)); |
||||
|
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); |
||||
|
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); |
||||
|
|
||||
|
vector<ofVec2f> 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); |
||||
|
|
||||
|
} // addTriangleSurface
|
||||
|
|
||||
|
void ofxPiMapper::addQuadSurface() { |
||||
|
|
||||
|
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; |
||||
|
|
||||
|
vector<ofVec2f> vertices; |
||||
|
float margin = 50.0f; |
||||
|
vertices.push_back(ofVec2f(margin, margin)); |
||||
|
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin)); |
||||
|
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); |
||||
|
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); |
||||
|
|
||||
|
vector<ofVec2f> texCoords; |
||||
|
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f))); |
||||
|
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f))); |
||||
|
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f))); |
||||
|
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f))); |
||||
|
|
||||
|
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
||||
|
|
||||
|
// select this surface right away
|
||||
|
surfaceManager.selectSurface(surfaceManager.size() - 1); |
||||
|
|
||||
|
} // addQuadSurface
|
||||
|
|
||||
|
ofx::piMapper::MediaServer& ofxPiMapper::getMediaServer() { |
||||
|
return mediaServer; |
||||
|
} |
||||
|
|
||||
|
ofx::piMapper::SurfaceManager& ofxPiMapper::getSurfaceManager() { |
||||
|
return surfaceManager; |
||||
|
} |
@ -1,6 +1,42 @@ |
|||||
#pragma once |
#pragma once |
||||
|
|
||||
|
#include "ofMain.h" |
||||
#include "SurfaceManager.h" |
#include "SurfaceManager.h" |
||||
#include "SurfaceManagerGui.h" |
#include "SurfaceManagerGui.h" |
||||
|
#include "MediaServer.h" |
||||
|
#include "FboSource.h" |
||||
|
|
||||
#include "MediaServer.h" |
#define PIMAPPER_DEF_SURFACES_XML_FILE "defaultSurfaces.xml" |
||||
|
#define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml" |
||||
|
|
||||
|
class ofxPiMapper { |
||||
|
public: |
||||
|
ofxPiMapper(); |
||||
|
~ofxPiMapper(); |
||||
|
|
||||
|
void setup(); |
||||
|
void draw(); // Called manually to make custom layering possible
|
||||
|
void keyPressed(ofKeyEventArgs& args); |
||||
|
|
||||
|
// Use this to add custom FBO source
|
||||
|
void addFboSource(ofx::piMapper::FboSource& fboSource); |
||||
|
|
||||
|
// TODO: Copy/move these methods to SurfaceManager
|
||||
|
void addTriangleSurface(); |
||||
|
void addQuadSurface(); |
||||
|
|
||||
|
// Toggle help / info
|
||||
|
void showInfo() { bShowInfo = true; }; |
||||
|
void hideInfo() { bShowInfo = false; }; |
||||
|
|
||||
|
// Getters
|
||||
|
ofx::piMapper::MediaServer& getMediaServer(); |
||||
|
ofx::piMapper::SurfaceManager& getSurfaceManager(); |
||||
|
|
||||
|
private: |
||||
|
bool isSetUp; |
||||
|
bool bShowInfo; |
||||
|
ofx::piMapper::MediaServer mediaServer; |
||||
|
ofx::piMapper::SurfaceManager surfaceManager; |
||||
|
ofx::piMapper::SurfaceManagerGui gui; |
||||
|
}; |
Loading…
Reference in new issue