Help rendering FBO to screen

I wrote up a little program over the weekend that renders squares to the screen (a cellular automata sandbox), and decided that I’d like to record some GIFs and videos of animations generated on screen, which seems to require me to render all my artifacts to an FBO, then pass that FBO’s pixel data to an add-on class.

Almost all of my code is being handled by a custom class (CA2D.h/cpp), so I’m curious if maybe there is something small I am missing about rendering FBOs to the screen from custom classes?

First I added an ofFbo object in my class header and initialized it using the procedure outlined in the oF documentation:

fbo.allocate(ofGetWidth(), ofGetHeight());


Next I wrapped all the data I want to render in the fbo begin() and end() functions like so:

void CA2D::render2D() {

    if(drawGrid) {

        // Draw the row lines
        for(int i=0; i<=columns; i++)
            ofLine(0, i*(cellSize+spacingY), columns*(cellSize+spacingX), i*(cellSize+spacingY));

        // Draw the column lines
        for(int i=0; i<=rows; i++)
            ofLine(i*(cellSize+spacingX), 0, i*(cellSize+spacingX), rows*(cellSize+spacingY));

    // Draw the cells
    for(int i=0; i<rows; i++) {
        for(int j=0; j<columns; j++) {
            int s = cells[i][j]->getState();
            if(s)   ofSetColor(255);
            else    ofSetColor(0);

            ofRect(cells[i][j]->getX()*(cellSize+spacingX), cells[i][j]->getY()*(cellSize+spacingY), cellSize, cellSize);




Then, in my ofApp::draw() function I call this function (ca->render2D()), expecting to have the FBO drawn to the screen. But I get nothing.

If I commet out the fbo.begin() and fbo.end() lines in this class function then everything renders just fine, but the FBO doesn’t seem to want to work.

Any ideas on what I’m missing?

have you tried ofClear(0, 255); ofSetColor(255, 255) after fbo.begin() ? maybe its an alpha thing?

Hi there!

Probably because of that if statement, the last ofSetColor() is zero. So everything gets drawn black. You should call ofSetColor(255) before fbo.draw(0,0). You can also do ofPush/Popstyle on the FBO.

Nice! Adding ofSetColor(255,255) just before the fbo.draw(0,0) worked great! Thanks!