Logic issues with FBO

hello

i’m having a logic problem with FBOs. My intention is to create a Canvas/Fbo class that will be instantiated as 4 objects. The goal with this is to create this template(some arbitrary scenes) that work independently, cause it might be controlled simultaneously by different users, each user with it’s own canvas/fbo.

i have created a canvas object that basically is a Fbo object. and have an array of 4 Canvases. mathematically it’s alright, but it’s not drawing anything on screen. i’m having trouble with the logic in instantiating these canvas/fbo objects.

thanks in advance

ofApp.h

#include "ofMain.h"
#include "Canvas.hpp"
#define NUMCANVAS 4

class ofApp : public ofBaseApp{

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

		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 mouseEntered(int x, int y);
		void mouseExited(int x, int y);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);
		
    Canvas groupOfCanvas[NUMCANVAS];
};

ofApp.cpp

void ofApp::setup(){
    int cols=2;
    int rows=2;
    int marginX=ofGetWidth()*0.1/4;
    int marginY=ofGetHeight()*0.1/4;
    std::cout << "marginX:" << marginX<< endl;
    std::cout << "marginY:" << marginX<< endl;
    int num=0;
    
    for(int x=0; x<cols; x++){
        for(int y=0; y<rows; y++){
            
            int posX=x*(ofGetWidth()/2)+marginX;
            int posY=y*(ofGetHeight()/2)+marginY;
            std::cout << "posX:" << posX<< endl;
            std::cout << "posY:" << posY<< endl;
            groupOfCanvas[num].setup(posX,posY,num);
            num++;
        }
    }

}

//--------------------------------------------------------------
void ofApp::update(){
    for(int i=0; i<NUMCANVAS; i++){
        groupOfCanvas[i].update();
    }
}

//--------------------------------------------------------------
void ofApp::draw(){
    for(int i=0; i<NUMCANVAS; i++){
        groupOfCanvas[i].draw();

    }
}

Canvas.hpp

#ifndef Canvas_hpp
#define Canvas_hpp

#include "ofMain.h"

class Canvas{
public:
    Canvas();
    void setup(int x, int y, int num);
    void update();
    void draw();
    void drawCanvas();
    
    ofFbo fbo;
    int fboId;
    int posX, posY, angle;
    int canvasW,canvasH;
    
   
    
};

#endif

Canvas.cpp

#include "Canvas.hpp"

Canvas::Canvas(){
};

void Canvas::setup(int x, int y, int num){
    fboId=num;
    posX=x;
    posY=y;
    canvasW=ofGetWidth()*.45;
    canvasH=ofGetHeight()*.45;
    std::cout << "canvasW:" << canvasW<< endl;
    std::cout << "canvasH:" << canvasH<< endl;
    
    fbo.allocate(canvasW,canvasH,GL_RGBA);
    
    fbo.begin();
    ofClear(255,128,0);
    fbo.end();
}

void Canvas::update(){
    
}

void Canvas::draw(){
    fbo.begin();
    drawCanvas();
    fbo.end();
}

void Canvas::drawCanvas(){
    ofSetColor(255,128,0);
    ofDrawRectangle(posX,posY,canvasW,canvasH);
    //ofDrawBitmapString(fboId, canvasW/2, canvasH/2);
}

It should be something like this:

void Canvas::draw(){
  //possibly some translation code here so that all of them don't draw on top of each other at 0, 0.
   fbo.draw(0, 0);
}

void Canvas::drawCanvas(){
    fbo.begin();
    ofClear(255, 255, 255, 0);

    ofSetColor(255,128,0);
    ofDrawRectangle(posX,posY,canvasW,canvasH);
    //ofDrawBitmapString(fboId, canvasW/2, canvasH/2);

    fbo.end();
}

You’re not actually drawing the fbo anywhere in your code, only drawing into it.

i’ve tried it, but still nothing shows. i’ve tried the solution that usually happens, that is to create a soecific function, drawCanvas(), and place it between fbo.begin() and fbo.end() in the draw().
just trying to figure out if the issue is within the draw functionof the ofApp. if i had to start/end the fbos there or if they work encapsulated within a class.

i can really make it work without FBOs, just commenting the fbo’s related stuff. i’ll probably discard them, but am still intrigued with the way it works, or why it didn’t work.

void Canvas::draw(){
    //fbo.begin();
    ofPushMatrix();
    ofTranslate(posX, posY);
    drawCanvas();
    ofPopMatrix();
    //fbo.end();
}

void Canvas::drawCanvas(){
    //ofClear(255,255,255,0);
    ofSetColor(255,128,0);
    ofDrawRectangle(0,0,canvasW,canvasH);
    ofSetColor(255);
    ofDrawBitmapString(fboId, canvasW/2, canvasH/2);
}