HELP: an ofFbo on a mesh... ô_ô WTF on my code?

Heeelllloooooooooooooooo everyone!

I’m a little newbie, but i’m trying to build a code with 3 fbo, like…

3 triangle (mesh), with 3view (fbo on mesh) of a 3D drawing (i take camera ribbon for it), but my code is not working yet: That’s why i’m asking:

Where did i make a mistake? Please… sensei? :smiley:

here, the code:

And thank you for everything that you can told about this little code ^^

the .h

#pragma once

#include “ofMain.h”

class testApp : public ofBaseApp{

public:
void setup();
void update();
void draw();

void customDraw3d();

void drawMainFbo();
void drawFbo1();
void drawFbo2();

void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);

int ecran = (ofGetWidth()/2);

ofFbo Mainfbo;
ofFbo fbo1;
ofFbo fbo2;

int MX = false;

ofCamera cam;
//this holds all of our points
vector points;
//this keeps track of the center of all the points
ofVec3f center;
ofMesh MainMesh;
ofMesh mesh1;
ofMesh mesh2;

};

the .cpp:

#include “testApp.h”

//--------------------------------------------------------------
void testApp::setup(){

ofBackground(50);
ofSetFrameRate(40);

//fbo
fbo1.allocate(ecran, ecran, GL_RGB);
fbo2.allocate(ecran, ecran, GL_RGB);
Mainfbo.allocate(ecran, ecran*2, GL_RGB);

}

//--------------------------------------------------------------
void testApp::update(){

//Dessin des fbo

fbo1.begin();
drawFbo1();
fbo1.end();

fbo2.begin();
drawFbo2();
fbo2.end();

Mainfbo.begin();
drawMainFbo();
Mainfbo.end();

////////////////////////////////////////////////////////////////

//fbo1.bind();
ofBeginShape();
mesh1.addVertex(ofVec3f(0,0,0));
mesh1.addVertex(ofVec3f(0,ofGetHeight(),0));
mesh1.addVertex(ofVec3f(ecran,ofGetHeight()/10,0));
mesh1.addVertex(ofVec3f(ecran,0,0));
ofEndShape();
//fbo1.unbind();

//fbo2.bind();
ofBeginShape();
mesh2.addVertex(ofVec3f(ofGetWidth(),0,0));
mesh2.addVertex(ofVec3f(ofGetWidth(),ofGetHeight(),0));
mesh2.addVertex(ofVec3f(ecran,ofGetHeight()/10,0));
mesh2.addVertex(ofVec3f(ecran,0,0));
ofEndShape();
//fbo2.unbind();

//Mainfbo.bind();
ofBeginShape();
MainMesh.addVertex(ofVec3f(0,ofGetHeight(),0));
MainMesh.addVertex(ofVec3f(ecran,ofGetHeight()/10,0));
MainMesh.addVertex(ofVec3f(ofGetWidth(),ofGetHeight(),0));
ofEndShape();
//Mainfbo.unbind();

////////////////////////////////////////////////////////////////

}

//--------------------- ENVIRRONEMENT 3D -----------------------
void testApp::customDraw3d(){

ofPushMatrix();

ofBox(30);

ofTranslate(-ecran, -ecran+130);

if (MX == true) {
ofRotate(ofGetMouseY());
}
else if (MX == false){

//-------------------------- TEST -----------------------------

ofSetColor(255,100,0);
//do the same thing from the first example…
ofMesh mesh;
mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
for(int i = 1; i < points.size(); i++){

//find this point and the next point
ofVec3f thisPoint = points[i-1];
ofVec3f nextPoint = points[i];

//get the direction from one to the next.
//the ribbon should fan out from this direction
ofVec3f direction = (nextPoint - thisPoint);

//get the distance from one point to the next
float distance = direction.length();

//get the normalized direction. normalized vectors always have a length of one
//and are really useful for representing directions as opposed to something with length
ofVec3f unitDirection = direction.normalized();

//find both directions to the left and to the right
ofVec3f toTheLeft = unitDirection.getRotated(-90, ofVec3f(0,0,1));
ofVec3f toTheRight = unitDirection.getRotated(90, ofVec3f(0,0,1));

//use the map function to determine the distance.
//the longer the distance, the narrower the line.
//this makes it look a bit like brush strokes
float thickness = ofMap(distance, 0, 30, 10, 1, true);

//calculate the points to the left and to the right
//by extending the current point in the direction of left/right by the length
ofVec3f leftPoint = thisPoint+toTheLeft*thickness;
ofVec3f rightPoint = thisPoint+toTheRight*thickness;

//add these points to the triangle strip
mesh.addVertex(ofVec3f(leftPoint.x, leftPoint.y, leftPoint.z));
mesh.addVertex(ofVec3f(rightPoint.x, rightPoint.y, rightPoint.z));
}

//end the shape
mesh.draw();

}

//-------------------------- TEST -----------------------------

ofPopMatrix();
}

//-------------------------- FBO 1 -----------------------------
void testApp::drawFbo1(){

//écran clair
ofClear(0,0,0, 0);

ofPushMatrix();
customDraw3d();
ofPopMatrix();

}
//-------------------------- FBO 2 -----------------------------

void testApp::drawFbo2(){

//écran clair
ofClear(0,0,0, 0);

ofPushMatrix();
customDraw3d();
ofPopMatrix();

}
//------------------------- MAIN FBO ---------------------------

void testApp::drawMainFbo(){

//écran clair
ofClear(0,0,0, 0);

ofPushMatrix();
ofTranslate(ecran/2,ecran/2,0);
customDraw3d();
ofPopMatrix();

}

//--------------------------------------------------------------
void testApp::draw(){

glEnable(GL_TRIANGLES);

Mainfbo.bind();
MainMesh.drawFaces();
Mainfbo.unbind();

fbo1.bind();
mesh1.drawFaces();
fbo1.bind();

fbo2.bind();
mesh2.drawFaces();
fbo2.bind();

//Pointeur souris.
ofFill();
ofSetColor(255, 0, 0);
ofSphere(ofGetMouseX(), ofGetMouseY(), 10);

}

//--------------------------------------------------------------
void testApp::keyPressed(int key){

int MX = true;

}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

ofVec3f mousePoint(x,y,0);
points.push_back(mousePoint);

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){

}

?

In your draw(), I’m not exactly sure what you are wanting to happen between the fbos and meshes.

You can either call fbo.draw() to see what is in the fbo, or mesh.draw()/drawFaces to see the mesh.

Each fbo is like its own little screen, if you want to draw the fbo on to a shape, you need to add texture coordinates [basically 0 -> width, 0 -> height] , then call fbo.getTextureReference().bind(), draw the mesh, then unbind() the texture ref, all in testApp::draw()

Yes it’s this: shape = screen and in the screen the 3D!

Sorry, but can you show me an exemple? really fast, i try but i think i miss something… >.<