diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index 14da4f2..b7304b5 100644 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -30,7 +30,27 @@ void ofApp::update() void ofApp::draw() { + // Check GUI mode - we want to see the texture that we are editing + // together with the actual surface being projection mapped. + + ofxSurfaceGui::editMode mode = gui.getMode(); + if ( mode == ofxSurfaceGui::TEXTURE_MAPPING ) { + // Draw texture of the surface in the background + //triangleSurface.getTexture()->draw(ofPoint(0,0)); + triangleSurface.drawTexture(ofVec2f(0, 0)); + + // Make the triangle surface transparent but still visible + // while we map the texture coordinates. + ofPushStyle(); + ofSetColor(255, 255, 255, 200); + } + triangleSurface.draw(); + + if ( mode == ofxSurfaceGui::TEXTURE_MAPPING ) { + ofPopStyle(); + } + gui.draw(); } diff --git a/src/ofxBaseSurface.cpp b/src/ofxBaseSurface.cpp index ffafbd3..42a5cbe 100644 --- a/src/ofxBaseSurface.cpp +++ b/src/ofxBaseSurface.cpp @@ -38,6 +38,24 @@ void ofxBaseSurface::createDefaultTexture() texture = &defaultTexture; } +void ofxBaseSurface::drawTexture(ofVec2f position) +{ + ofMesh texMesh; + texMesh.addVertex(position); + texMesh.addVertex(position + ofVec2f(texture->getWidth(), 0.0f)); + texMesh.addVertex(position + ofVec2f(texture->getWidth(), texture->getHeight())); + texMesh.addVertex(position + ofVec2f(0.0f, texture->getHeight())); + texMesh.addTriangle(0, 2, 3); + texMesh.addTriangle(0, 1, 2); + texMesh.addTexCoord(ofVec2f(0.0f, 0.0f)); + texMesh.addTexCoord(ofVec2f(1.0f, 0.0f)); + texMesh.addTexCoord(ofVec2f(1.0f, 1.0f)); + texMesh.addTexCoord(ofVec2f(0.0f, 1.0f)); + texture->bind(); + texMesh.draw(); + texture->unbind(); +} + ofTexture* ofxBaseSurface::getTexture() { return texture; diff --git a/src/ofxBaseSurface.h b/src/ofxBaseSurface.h index 89bc9c6..2fd60d6 100644 --- a/src/ofxBaseSurface.h +++ b/src/ofxBaseSurface.h @@ -12,6 +12,9 @@ public: virtual void setVertex(int index, ofVec2f p){}; virtual void setTexCoord(int index, ofVec2f t){}; + // Draws a texture using ofMesh + void drawTexture(ofVec2f position); + ofTexture* getTexture(); protected: