Quantcast
Viewing all articles
Browse latest Browse all 4929

Logic issues with FBO

@eduzal wrote:

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

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles