diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index b0c6ee6..85c08d1 100644 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -2,7 +2,8 @@ void ofApp::setup() { - cout << "Hello World!" << endl; + // Create a triangle surface + triangleSurface.setup( ofVec2f(30,40), ofVec2f(500,500), ofVec2f(0,600) ); } void ofApp::update() @@ -12,7 +13,7 @@ void ofApp::update() void ofApp::draw() { - ofRect(100, 100, ofGetWidth()-200, ofGetHeight()-200); + triangleSurface.draw(); } void ofApp::keyPressed(int key) diff --git a/src/ofxBaseSurface.cpp b/src/ofxBaseSurface.cpp new file mode 100644 index 0000000..3f73333 --- /dev/null +++ b/src/ofxBaseSurface.cpp @@ -0,0 +1 @@ +#include "ofxBaseSurface.h" \ No newline at end of file diff --git a/src/ofxBaseSurface.h b/src/ofxBaseSurface.h new file mode 100644 index 0000000..def7efe --- /dev/null +++ b/src/ofxBaseSurface.h @@ -0,0 +1,17 @@ +#ifndef H_OFX_BASE_SURFACE +#define H_OFX_BASE_SURFACE + +#include "ofMain.h" + +class ofxBaseSurface +{ +public: + virtual void setup(){}; + virtual void draw(){}; + +protected: + ofMesh mesh; + ofTexture* texture; +}; + +#endif \ No newline at end of file diff --git a/src/ofxTriangleSurface.cpp b/src/ofxTriangleSurface.cpp index 64f7eb4..e769651 100644 --- a/src/ofxTriangleSurface.cpp +++ b/src/ofxTriangleSurface.cpp @@ -3,9 +3,36 @@ ofxTriangleSurface::ofxTriangleSurface() { cout << "ofxTriangleSurface constructor." << endl; + setup(); } ofxTriangleSurface::~ofxTriangleSurface() { cout << "ofxTriangleSurface destructor." << endl; +} + +void ofxTriangleSurface::setup() +{ + // Create 3 points for the triangle + ofVec2f p1 = ofVec2f(ofGetWidth()/2.0f, 0); + ofVec2f p2 = ofVec2f(ofVec2f(0, ofGetHeight())); + ofVec2f p3 = ofVec2f(ofGetWidth(), ofGetHeight()); + + setup( p1, p2, p3 ); +} + +void ofxTriangleSurface::setup( ofVec2f p1, ofVec2f p2, ofVec2f p3 ) +{ + // Clear previous vertices if any + mesh.clear(); + + // Create a surface with the points + mesh.addVertex( p1 ); + mesh.addVertex( p2 ); + mesh.addVertex( p3 ); +} + +void ofxTriangleSurface::draw() +{ + mesh.draw(); } \ No newline at end of file diff --git a/src/ofxTriangleSurface.h b/src/ofxTriangleSurface.h index 19a516e..b34aa00 100644 --- a/src/ofxTriangleSurface.h +++ b/src/ofxTriangleSurface.h @@ -2,12 +2,17 @@ #define H_OFX_TRIANGLE_SURFACE #include "ofMain.h" +#include "ofxBaseSurface.h" -class ofxTriangleSurface +class ofxTriangleSurface : public ofxBaseSurface { public: ofxTriangleSurface(); ~ofxTriangleSurface(); + + void setup(); + void setup( ofVec2f p1, ofVec2f p2, ofVec2f p3 ); + void draw(); }; #endif \ No newline at end of file