diff --git a/example/bin/.gitignore b/example/bin/.gitignore
index a4a7aed..e2b3e9d 100644
--- a/example/bin/.gitignore
+++ b/example/bin/.gitignore
@@ -1,3 +1,3 @@
*.app
data/*.jpg
-data/*.xml
+data/settings.xml
diff --git a/example/bin/data/surfaces.xml b/example/bin/data/surfaces.xml
new file mode 100644
index 0000000..9e94bfb
--- /dev/null
+++ b/example/bin/data/surfaces.xml
@@ -0,0 +1,104 @@
+
+
+
+
+ 300.000000000
+ 0.000000000
+
+
+ 0.000000000
+ 500.000000000
+
+
+ 600.000000000
+ 500.000000000
+
+
+
+
+ 0.500000000
+ 0.000000000
+
+
+ 0.000000000
+ 1.000000000
+
+
+ 1.000000000
+ 1.000000000
+
+
+
+ image
+ none
+
+
+
+
+
+ 24.000000000
+ 33.000000000
+
+
+ 566.000000000
+ 35.000000000
+
+
+ 207.000000000
+ 310.000000000
+
+
+
+
+ 0.500000000
+ 0.000000000
+
+
+ 0.000000000
+ 1.000000000
+
+
+ 1.000000000
+ 1.000000000
+
+
+
+ image
+ image5.jpg
+
+
+
+
+
+ 74.709846497
+ 448.636596680
+
+
+ 564.630920410
+ 201.926849365
+
+
+ 23.396121979
+ 257.170288086
+
+
+
+
+ 0.981523871
+ 0.471785098
+
+
+ 0.245601788
+ 0.110941604
+
+
+ 0.662217021
+ 0.714698017
+
+
+
+ image
+ image4.jpg
+
+
+
diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp
index 83228f7..42d3982 100644
--- a/example/src/ofApp.cpp
+++ b/example/src/ofApp.cpp
@@ -5,12 +5,16 @@ void ofApp::setup()
image.loadImage("TestPatternInvert.jpg");
bShowInfo = false;
+ /*
surfaceManager.addSurface( ofxSurfaceType::TRIANGLE_SURFACE );
surfaceManager.addSurface( ofxSurfaceType::TRIANGLE_SURFACE );
surfaceManager.getSurface(1)->setVertex(0, ofVec2f(10, 10));
surfaceManager.getSurface(1)->setVertex(1, ofVec2f(400, 20));
surfaceManager.getSurface(1)->setVertex(2, ofVec2f(300, 400));
+ */
+
+ surfaceManager.loadXmlSettings("surfaces.xml");
gui.setSurfaceManager( &surfaceManager );
}
diff --git a/src/ofxSurfaceManager.cpp b/src/ofxSurfaceManager.cpp
index 6293387..f01e532 100644
--- a/src/ofxSurfaceManager.cpp
+++ b/src/ofxSurfaceManager.cpp
@@ -184,7 +184,85 @@ void ofxSurfaceManager::saveXmlSettings(string fileName)
void ofxSurfaceManager::loadXmlSettings(string fileName)
{
+ if (!xmlSettings.loadFile(fileName)){
+ ofLog(OF_LOG_WARNING, "Could not load XML settings.");
+ return;
+ }
+
+ if (!xmlSettings.tagExists("surfaces")){
+ ofLog(OF_LOG_WARNING, "XML settings is empty or has wrong markup.");
+ return;
+ }
+
+ xmlSettings.pushTag("surfaces");
+
+ int numSurfaces = xmlSettings.getNumTags("surface");
+ for ( int i=0; i vertices;
+
+ xmlSettings.pushTag("vertex", 0);
+ vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) );
+ xmlSettings.popTag();
+
+ xmlSettings.pushTag("vertex", 1);
+ vertices.push_back( ofVec2f( xmlSettings.getValue("x", 100.0f), xmlSettings.getValue("y", 0.0f) ) );
+ xmlSettings.popTag();
+
+ xmlSettings.pushTag("vertex", 2);
+ vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 100.0f) ) );
+ xmlSettings.popTag();
+
+ xmlSettings.popTag(); // vertices
+
+ // get texture coordinates (only for triangle surfaces for now)
+ xmlSettings.pushTag("texCoords");
+
+ vector texCoords;
+
+ xmlSettings.pushTag("texCoord", 0);
+ texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) );
+ xmlSettings.popTag();
+
+ xmlSettings.pushTag("texCoord", 1);
+ texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 1.0f), xmlSettings.getValue("y", 0.0f) ) );
+ xmlSettings.popTag();
+
+ xmlSettings.pushTag("texCoord", 2);
+ texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 1.0f) ) );
+ xmlSettings.popTag();
+
+ xmlSettings.popTag(); // texCoords
+
+
+ // now we have variables sourceName and sourceTexture
+ // by checking those we can use one or another addSurface method
+ if ( sourceName != "none" && sourceTexture != NULL ) {
+ addSurface(ofxSurfaceType::TRIANGLE_SURFACE, sourceTexture, vertices, texCoords);
+ } else {
+ addSurface(ofxSurfaceType::TRIANGLE_SURFACE, vertices, texCoords);
+ }
+
+ xmlSettings.popTag(); // surface
+ }
+ xmlSettings.popTag(); // surfaces
}
ofxBaseSurface* ofxSurfaceManager::selectSurface(int index)
@@ -218,7 +296,9 @@ ofTexture* ofxSurfaceManager::loadImageSource(string name, string path)
// not loaded - load
ofImage* image = new ofImage();
- image->loadImage(path);
+ if ( !image->loadImage(path) ){
+ return NULL;
+ }
loadedImageSources.push_back(image);
loadedImageSourceNames.push_back(name);
return &image->getTextureReference();