Browse Source

Replace main example with the fboTexture one

master
Krisjanis Rijnieks 11 years ago
parent
commit
50e757a225
  1. 1
      .gitignore
  2. 6
      example-fboTexture/.gitignore
  3. 13
      example-fboTexture/Makefile
  4. 3
      example-fboTexture/addons.make
  5. 4
      example-fboTexture/bin/.gitignore
  6. 138
      example-fboTexture/bin/data/defaultSurfaces.xml
  7. BIN
      example-fboTexture/bin/data/sources/images/image1.jpg
  8. BIN
      example-fboTexture/bin/data/sources/images/image2.jpg
  9. BIN
      example-fboTexture/bin/data/sources/images/image3.jpg
  10. BIN
      example-fboTexture/bin/data/sources/images/image4.jpg
  11. BIN
      example-fboTexture/bin/data/sources/images/image5.jpg
  12. 12
      example-fboTexture/src/main.cpp
  13. 164
      example-fboTexture/src/ofApp.cpp
  14. 31
      example-fboTexture/src/ofApp.h
  15. 0
      example/bin/data/defaultSurfaces.xml
  16. 101
      example/src/ofApp.cpp
  17. 9
      example/src/ofApp.h

1
.gitignore

@ -1 +1,2 @@
.DS_Store
example-*

6
example-fboTexture/.gitignore

@ -1,6 +0,0 @@
obj
*.xcodeproj
*.plist
*.xcconfig
*~
config.make

13
example-fboTexture/Makefile

@ -1,13 +0,0 @@
# Attempt to load a config.make file.
# If none is found, project defaults in config.project.make will be used.
ifneq ($(wildcard config.make),)
include config.make
endif
# make sure the the OF_ROOT location is defined
ifndef OF_ROOT
OF_ROOT=../../..
endif
# call the project makefile!
include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk

3
example-fboTexture/addons.make

@ -1,3 +0,0 @@
ofxPiMapper
ofxUI
ofxXmlSettings

4
example-fboTexture/bin/.gitignore

@ -1,4 +0,0 @@
*.app
data/*.jpg
data/settings.xml
data/surfaces.xml

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

@ -1,138 +0,0 @@
<surfaces>
<surface>
<vertices>
<vertex>
<x>250.000000000</x>
<y>34.000000000</y>
</vertex>
<vertex>
<x>374.000000000</x>
<y>201.000000000</y>
</vertex>
<vertex>
<x>535.000000000</x>
<y>35.000000000</y>
</vertex>
</vertices>
<texCoords>
<texCoord>
<x>0.101999998</x>
<y>0.335999995</y>
</texCoord>
<texCoord>
<x>0.328000009</x>
<y>0.689999998</y>
</texCoord>
<texCoord>
<x>0.705999970</x>
<y>0.393999994</y>
</texCoord>
</texCoords>
<source>
<source-type>image</source-type>
<source-name>image1.jpg</source-name>
</source>
</surface>
<surface>
<vertices>
<vertex>
<x>24.396121979</x>
<y>259.170288086</y>
</vertex>
<vertex>
<x>250.000000000</x>
<y>34.000000000</y>
</vertex>
<vertex>
<x>214.630920410</x>
<y>282.926849365</y>
</vertex>
</vertices>
<texCoords>
<texCoord>
<x>0.251666665</x>
<y>0.090000004</y>
</texCoord>
<texCoord>
<x>0.449999988</x>
<y>0.696666658</y>
</texCoord>
<texCoord>
<x>0.870000005</x>
<y>0.173333332</y>
</texCoord>
</texCoords>
<source>
<source-type>image</source-type>
<source-name>image5.jpg</source-name>
</source>
</surface>
<surface>
<vertices>
<vertex>
<x>75.709846497</x>
<y>450.636596680</y>
</vertex>
<vertex>
<x>214.630920410</x>
<y>282.926849365</y>
</vertex>
<vertex>
<x>24.396121979</x>
<y>259.170288086</y>
</vertex>
</vertices>
<texCoords>
<texCoord>
<x>0.981523871</x>
<y>0.471785098</y>
</texCoord>
<texCoord>
<x>0.245601788</x>
<y>0.110941604</y>
</texCoord>
<texCoord>
<x>0.662217021</x>
<y>0.714698017</y>
</texCoord>
</texCoords>
<source>
<source-type>image</source-type>
<source-name>image4.jpg</source-name>
</source>
</surface>
<surface>
<vertices>
<vertex>
<x>527.148498535</x>
<y>277.815002441</y>
</vertex>
<vertex>
<x>320.170959473</x>
<y>461.102355957</y>
</vertex>
<vertex>
<x>285.250427246</x>
<y>209.424682617</y>
</vertex>
</vertices>
<texCoords>
<texCoord>
<x>0.031067841</x>
<y>0.511202157</y>
</texCoord>
<texCoord>
<x>0.450178742</x>
<y>0.116164304</y>
</texCoord>
<texCoord>
<x>0.543386877</x>
<y>0.609848201</y>
</texCoord>
</texCoords>
<source>
<source-type>image</source-type>
<source-name>none</source-name>
</source>
</surface>
</surfaces>

BIN
example-fboTexture/bin/data/sources/images/image1.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 KiB

BIN
example-fboTexture/bin/data/sources/images/image2.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 260 KiB

BIN
example-fboTexture/bin/data/sources/images/image3.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 KiB

BIN
example-fboTexture/bin/data/sources/images/image4.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

BIN
example-fboTexture/bin/data/sources/images/image5.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 KiB

12
example-fboTexture/src/main.cpp

@ -1,12 +0,0 @@
#include "ofMain.h"
#include "ofApp.h"
int main()
{
#ifdef TARGET_RASPBERRY_PI
ofSetupOpenGL(600, 500, OF_FULLSCREEN);
#else
ofSetupOpenGL(600, 500, OF_WINDOW);
#endif
ofRunApp(new ofApp());
}

164
example-fboTexture/src/ofApp.cpp

@ -1,164 +0,0 @@
#include "ofApp.h"
void ofApp::setup()
{
bShowInfo = false;
// check if the surfaces.xml file is there
// if not - load defaultSurfaces.xml
if ( ofFile::doesFileExist("surfaces.xml") ) {
surfaceManager.loadXmlSettings("surfaces.xml");
} else {
surfaceManager.loadXmlSettings("defaultSurfaces.xml");
}
// Pass the surface manager to the mapper graphical user interface
gui.setSurfaceManager( &surfaceManager );
// Create FBO
fbo = new ofFbo();
fbo->allocate( 500, 500 );
setFboAsTexture();
// Genereate rects
int numRects = 20; // change this to add more or less rects
for ( int i=0; i<numRects; i++ ) {
rects.push_back( ofRectangle(0, ofRandom(fbo->getHeight()), fbo->getWidth(), ofRandom(20)) );
rectSpeeds.push_back( (1.0f + ofRandom(5)) );
}
}
void ofApp::update()
{
// Move rects
for ( int i=0; i<rects.size(); i++ ) {
rects[i].y += rectSpeeds[i];
if ( rects[i].y > fbo->getHeight() ) {
rects[i].y = -rects[i].getHeight();
}
}
// Fill FBO
fbo->begin();
ofClear(0);
ofBackground(0);
ofSetColor(255);
for ( int i=0; i<rects.size(); i++ ) {
ofRect( rects[i] );
}
fbo->end();
}
void ofApp::draw()
{
// Draw the piMapper GUI
gui.draw();
if ( bShowInfo ) {
// Draw instructions
stringstream ss;
ss << "There are 4 modes:\n\n";
ss << " 1. Presentation mode\n";
ss << " 2. Texture mapping mode\n";
ss << " 3. Projection mapping mode\n";
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";
ss << "Hit <i> to hide this message.";
ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0,0,0,100), ofColor(255,255,255,200));
}
}
void ofApp::exit()
{
// Clear FBO from mem
delete fbo;
}
void ofApp::keyPressed(int key)
{
cout << "Key pressed: " << static_cast<char>(key) << endl;
switch (key) {
case '1': gui.setMode(ofxGuiMode::NONE); break;
case '2': gui.setMode(ofxGuiMode::TEXTURE_MAPPING); break;
case '3': gui.setMode(ofxGuiMode::PROJECTION_MAPPING); break;
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;
case 'a': setFboAsTexture(); break;
case OF_KEY_BACKSPACE: surfaceManager.removeSelectedSurface(); break;
default: break;
}
}
void ofApp::addRandomSurface()
{
int surfaceType = ofxSurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices;
vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) );
vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) );
vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) );
vector<ofVec2f> texCoords;
texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) );
texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) );
texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) );
surfaceManager.addSurface(surfaceType, vertices, texCoords);
// select this surface right away
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;
vector<ofVec2f> vertices;
vertices.push_back( ofVec2f( (float)ofGetWidth()/2.0f, 0.0f ) );
vertices.push_back( ofVec2f( (float)ofGetWidth(), (float)ofGetHeight() ) );
vertices.push_back( ofVec2f( 0.0f, (float)ofGetHeight() ) );
vector<ofVec2f> texCoords;
texCoords.push_back( ofVec2f( 0.5f, 0.0f ) );
texCoords.push_back( ofVec2f( 1.0f, 1.0f ) );
texCoords.push_back( ofVec2f( 0.0f, 1.0f ) );
surfaceManager.addSurface(surfaceType, vertices, texCoords);
// select this surface right away
surfaceManager.selectSurface(surfaceManager.size()-1);
}
void ofApp::setFboAsTexture()
{
surfaceManager.getSurface(0)->setTexture( &fbo->getTextureReference() );
}

31
example-fboTexture/src/ofApp.h

@ -1,31 +0,0 @@
#ifndef H_OF_APP
#define H_OF_APP
#include "ofMain.h"
#include "ofxPiMapper.h"
class ofApp : public ofBaseApp
{
public:
void setup();
void update();
void draw();
void exit();
void keyPressed(int key);
void addRandomSurface();
void addQuadSurface();
void addSurface();
void setFboAsTexture();
ofImage image;
ofxSurfaceManager surfaceManager;
ofxSurfaceManagerGui gui;
bool bShowInfo;
ofFbo* fbo;
vector<ofRectangle> rects;
vector<float> rectSpeeds;
};
#endif

0
example/bin/data/defaultSurfaces.xml

101
example/src/ofApp.cpp

@ -2,39 +2,56 @@
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));
*/
// check if the surfaces.xml file is there
// if not - load defaultSurfaces.xml
if ( ofFile::doesFileExist("surfaces.xml") ) {
surfaceManager.loadXmlSettings("surfaces.xml");
} else {
surfaceManager.loadXmlSettings("defaultSurfaces.xml");
}
// Pass the surface manager to the mapper graphical user interface
gui.setSurfaceManager( &surfaceManager );
// Create FBO
fbo = new ofFbo();
fbo->allocate( 500, 500 );
setFboAsTexture();
// Genereate rects
int numRects = 20; // change this to add more or less rects
for ( int i=0; i<numRects; i++ ) {
rects.push_back( ofRectangle(0, ofRandom(fbo->getHeight()), fbo->getWidth(), ofRandom(20)) );
rectSpeeds.push_back( (1.0f + ofRandom(5)) );
}
}
void ofApp::update()
{
ofBackground(0);
// Move rects
for ( int i=0; i<rects.size(); i++ ) {
rects[i].y += rectSpeeds[i];
if ( rects[i].y > fbo->getHeight() ) {
rects[i].y = -rects[i].getHeight();
}
}
// Fill FBO
fbo->begin();
ofClear(0);
ofBackground(0);
ofSetColor(255);
for ( int i=0; i<rects.size(); i++ ) {
ofRect( rects[i] );
}
fbo->end();
}
void ofApp::draw()
{
//surfaceManager.draw();
// if using gui - use ofxSurfaceManagerGui::draw() instead of surfaceManager::draw()
// Draw the piMapper GUI
gui.draw();
if ( bShowInfo ) {
@ -47,14 +64,22 @@ 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";
ss << "Hit <i> to hide this message.";
ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0,0,0,100), ofColor(255,255,255,200));
}
}
void ofApp::exit()
{
// Clear FBO from mem
delete fbo;
}
void ofApp::keyPressed(int key)
{
cout << "Key pressed: " << static_cast<char>(key) << endl;
@ -66,32 +91,16 @@ 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;
case 'a': setFboAsTexture(); break;
case OF_KEY_BACKSPACE: surfaceManager.removeSelectedSurface(); break;
default: break;
}
}
void ofApp::mousePressed(int x, int y, int button)
{
//cout << "Mouse pressed." << endl;
//surfaceManager.mousePressed(x, y, button);
}
void ofApp::mouseReleased(int x, int y, int button)
{
//cout << "Mouse released." << endl;
//surfaceManager.mouseReleased(x, y, button);
}
void ofApp::mouseDragged(int x, int y, int button)
{
//
//surfaceManager.mouseDragged(x, y, button);
}
void ofApp::addRandomSurface()
{
int surfaceType = ofxSurfaceType::TRIANGLE_SURFACE;
@ -109,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;
@ -124,4 +156,9 @@ void ofApp::addSurface()
// select this surface right away
surfaceManager.selectSurface(surfaceManager.size()-1);
}
void ofApp::setFboAsTexture()
{
surfaceManager.getSurface(0)->setTexture( &fbo->getTextureReference() );
}

9
example/src/ofApp.h

@ -10,19 +10,22 @@ public:
void setup();
void update();
void draw();
void exit();
void keyPressed(int key);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseDragged(int x, int y, int button);
void addRandomSurface();
void addQuadSurface();
void addSurface();
void setFboAsTexture();
ofImage image;
ofxSurfaceManager surfaceManager;
ofxSurfaceManagerGui gui;
bool bShowInfo;
ofFbo* fbo;
vector<ofRectangle> rects;
vector<float> rectSpeeds;
};
#endif
Loading…
Cancel
Save