Browse Source

modified: example-fboTexture/bin/data/defaultSurfaces.xml

modified:   example-fboTexture/src/ofApp.cpp
	modified:   example-fboTexture/src/ofApp.h
	modified:   src/ofxProjectionEditor.h
	modified:   src/ofxSurfaceManager.cpp
	modified:   src/ofxSurfaceManager.h
	modified:   src/ofxSurfaceType.h
	modified:   src/ofxTextureEditor.cpp
	src/ofxQuadSurface.cpp
	src/ofxQuadSurface.h
master
sebl 11 years ago
parent
commit
b674303dc4
  1. 0
      example-fboTexture/bin/data/defaultSurfaces.xml
  2. 25
      example-fboTexture/src/ofApp.cpp
  3. 1
      example-fboTexture/src/ofApp.h
  4. 0
      src/ofxProjectionEditor.h
  5. 234
      src/ofxSurfaceManager.cpp
  6. 1
      src/ofxSurfaceManager.h
  7. 3
      src/ofxSurfaceType.h
  8. 0
      src/ofxTextureEditor.cpp

0
example-fboTexture/bin/data/defaultSurfaces.xml

25
example-fboTexture/src/ofApp.cpp

@ -64,6 +64,7 @@ void ofApp::draw()
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";
@ -90,6 +91,7 @@ void ofApp::keyPressed(int key)
case '4': gui.setMode(ofxGuiMode::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;
@ -116,6 +118,29 @@ void ofApp::addRandomSurface()
surfaceManager.selectSurface(surfaceManager.size()-1);
}
void ofApp::addQuadSurface()
{
int surfaceType = ofxSurfaceType::QUAD_SURFACE;
vector<ofVec2f> vertices;
int border = 50;
vertices.push_back( ofVec2f(border, border) );
vertices.push_back( ofVec2f(border, ofGetHeight() - border) );
vertices.push_back( ofVec2f(ofGetWidth() - border, ofGetHeight() - border) );
vertices.push_back( ofVec2f(ofGetWidth() - border, 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 = ofxSurfaceType::TRIANGLE_SURFACE;

1
example-fboTexture/src/ofApp.h

@ -15,6 +15,7 @@ public:
void keyPressed(int key);
void addRandomSurface();
void addQuadSurface();
void addSurface();
void setFboAsTexture();

0
src/ofxProjectionEditor.h

234
src/ofxSurfaceManager.cpp

@ -21,7 +21,11 @@ void ofxSurfaceManager::addSurface(int surfaceType)
{
if ( surfaceType == ofxSurfaceType::TRIANGLE_SURFACE ) {
surfaces.push_back( new ofxTriangleSurface() );
} else {
}
else if (surfaceType == ofxSurfaceType::QUAD_SURFACE ) {
surfaces.push_back( new ofxQuadSurface() );
}
else {
throw std::runtime_error("Attempt to add non-existing surface type.");
}
}
@ -31,7 +35,12 @@ void ofxSurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr)
if ( surfaceType == ofxSurfaceType::TRIANGLE_SURFACE ) {
surfaces.push_back( new ofxTriangleSurface() );
surfaces.back()->setTexture(texturePtr);
} else {
}
else if (surfaceType == ofxSurfaceType::QUAD_SURFACE ) {
surfaces.push_back( new ofxQuadSurface() );
surfaces.back()->setTexture(texturePtr);
}
else {
throw std::runtime_error("Attempt to add non-existing surface type.");
}
}
@ -43,7 +52,7 @@ void ofxSurfaceManager::addSurface(int surfaceType, vector<ofVec2f> vertices, ve
if ( vertices.size() < 3 ) {
throw std::runtime_error("There must be 3 vertices for a triangle surface.");
} else if (texCoords.size() < 3) {
throw std::runtime_error("Thre must be 3 texture coordinates for a triangle surface.");
throw std::runtime_error("There must be 3 texture coordinates for a triangle surface.");
}
surfaces.push_back( new ofxTriangleSurface() );
@ -53,7 +62,22 @@ void ofxSurfaceManager::addSurface(int surfaceType, vector<ofVec2f> vertices, ve
surfaces.back()->setTexCoord(i, texCoords[i]);
}
} else {
}
else if (surfaceType == ofxSurfaceType::QUAD_SURFACE ) {
if ( vertices.size() < 4 ) {
throw std::runtime_error("There must be 4 vertices for a quad surface.");
} else if (texCoords.size() < 4) {
throw std::runtime_error("There must be 4 texture coordinates for a quad surface.");
}
surfaces.push_back( new ofxQuadSurface() );
for ( int i=0; i<4; i++ ) {
surfaces.back()->setVertex(i, vertices[i]);
surfaces.back()->setTexCoord(i, texCoords[i]);
}
}
else {
throw std::runtime_error("Attempt to add non-existing surface type.");
}
@ -77,7 +101,23 @@ void ofxSurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr, vecto
surfaces.back()->setTexCoord(i, texCoords[i]);
}
} else {
}
else if (surfaceType == ofxSurfaceType::QUAD_SURFACE ) {
if ( vertices.size() < 4 ) {
throw std::runtime_error("There must be 4 vertices for a quad surface.");
} else if (texCoords.size() < 4) {
throw std::runtime_error("Thre must be 4 texture coordinates for a quad surface.");
}
surfaces.push_back( new ofxQuadSurface() );
surfaces.back()->setTexture(texturePtr);
for ( int i=0; i<4; i++ ) {
surfaces.back()->setVertex(i, vertices[i]);
surfaces.back()->setTexCoord(i, texCoords[i]);
}
}
else {
throw std::runtime_error("Attempt to add non-existing surface type.");
}
}
@ -138,6 +178,16 @@ void ofxSurfaceManager::clear()
}
}
// String getTypeString(ofxSurfaceType e)
// {
// switch e
// {
// case TRINAGLE_SURFACE: return "TRINAGLE_SURFACE";
// case QUAD_SURFACE: return "QUAD_SURFACE";
// default: throw Exception("Bad MyEnum");
// }
// }
void ofxSurfaceManager::saveXmlSettings(string fileName)
{
xmlSettings.clear();
@ -147,10 +197,9 @@ void ofxSurfaceManager::saveXmlSettings(string fileName)
xmlSettings.pushTag("surfaces");
for ( int i=0; i<surfaces.size(); i++ ) {
xmlSettings.addTag("surface");
xmlSettings.addTag("surface");
xmlSettings.pushTag("surface", i);
ofxBaseSurface* surface = surfaces[i];
xmlSettings.addTag("vertices");
xmlSettings.pushTag("vertices");
vector<ofVec3f>* vertices = &surface->getVertices();
@ -186,9 +235,16 @@ void ofxSurfaceManager::saveXmlSettings(string fileName)
xmlSettings.addValue("source-type", "image");
xmlSettings.addValue("source-name", getSurfaceSourceName(surface));
//xmlSettings.addValue("source-path", "/root/etc/image.jpg");
xmlSettings.popTag(); // source
// xmlSettings.addTag("type");
// xmlSettings.pushTag("type");
// // surfaceType == ofxSurfaceType::TRIANGLE_SURFACE
// ofxSurfaceType surfaceType = &surface->getType();
// xmlSettings.addValue("surface-type", surfaceType);
// xmlSettings.popTag(); // type
xmlSettings.popTag(); // surface
}
xmlSettings.popTag(); // surfaces
@ -198,6 +254,8 @@ void ofxSurfaceManager::saveXmlSettings(string fileName)
void ofxSurfaceManager::loadXmlSettings(string fileName)
{
ofLog(OF_LOG_WARNING, "A load XML settings...");
if (!xmlSettings.loadFile(fileName)){
ofLog(OF_LOG_WARNING, "Could not load XML settings.");
return;
@ -225,55 +283,125 @@ void ofxSurfaceManager::loadXmlSettings(string fileName)
sourceTexture = loadImageSource(sourceName, ss.str());
}
xmlSettings.popTag(); // source
// // attempt to load surface type
// ofLog(OF_LOG_WARNING, "Attempt to load surface type.");
// xmlSettings.pushTag("type");
// string surfaceType = xmlSettings.getValue("surface-type", "TRIANGLE_SURFACE");
// xmlSettings.popTag(); // type
// get vertices (only for triangle surface for now)
xmlSettings.pushTag("vertices");
vector<ofVec2f> 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<ofVec2f> 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);
int vertexCount = vertices.size();
// int vertexCount = vertices->size()
//it's a triangle ?
if (vertexCount == 3)
// if (surfaceType == TRIANGLE_SURFACE)
{
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
xmlSettings.pushTag("texCoords");
vector<ofVec2f> 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
}
// it's a quad ?
else if (vertexCount == 4)
// if (surface-type == QUAD_SURFACE)
{
ofSendMessage("create Quad");
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", 100.0f), xmlSettings.getValue("y", 100.0f) ) );
xmlSettings.popTag();
xmlSettings.pushTag("vertex", 3);
vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 100.0f) ) );
xmlSettings.popTag();
xmlSettings.popTag(); // vertices
xmlSettings.pushTag("texCoords");
vector<ofVec2f> 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", 1.0f), xmlSettings.getValue("y", 1.0f) ) );
xmlSettings.popTag();
xmlSettings.pushTag("texCoord", 3);
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::QUAD_SURFACE, sourceTexture, vertices, texCoords);
} else {
addSurface(ofxSurfaceType::QUAD_SURFACE, vertices, texCoords);
}
xmlSettings.popTag(); // surface
}
xmlSettings.popTag(); // surface
}
xmlSettings.popTag(); // surfaces

1
src/ofxSurfaceManager.h

@ -3,6 +3,7 @@
#include "ofxBaseSurface.h"
#include "ofxTriangleSurface.h"
#include "ofxQuadSurface.h"
#include "ofxSurfaceType.h"
#include "ofEvents.h"
#include "ofxXmlSettings.h"

3
src/ofxSurfaceType.h

@ -4,7 +4,8 @@
struct ofxSurfaceType
{
enum {
TRIANGLE_SURFACE
TRIANGLE_SURFACE,
QUAD_SURFACE
};
};

0
src/ofxTextureEditor.cpp

Loading…
Cancel
Save