Browse Source

Add texture drawing on texture mapping edit mode and semi-transparent projection mapped surface over it

master
Krisjanis Rijnieks 11 years ago
parent
commit
da232790ba
  1. 20
      example/src/ofApp.cpp
  2. 18
      src/ofxBaseSurface.cpp
  3. 3
      src/ofxBaseSurface.h

20
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();
}

18
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;

3
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:

Loading…
Cancel
Save