Looking for a little more explanation into ofFbo

Hi All

I have a little confusion with ofFbo. currently i understand it as using the frame rate almost as a for loop to draw objects (please correct me if im wrong).

My problem lies with trying to speed up my code, a particle system, after ive written a ton of for loops.

another thing im struggling to grasp is how do i use it in the classes i create?
for example, I’ve created a particle class with a Particle.draw() function , where do i put all this stuff : Fbo.allocate(ofGetWidth(), ofGetHeight());

and where do i initilise the fbo class? in the main or the class?

heres my particle class header file

#pragma once
#include "ofMain.h"

class Particle

	ofVec2f position;
	ofVec2f velocity;
	ofVec2f acceleration;
	ofVec2f gravity = ofVec2f(0.0,0.1);
	int p_radius = 2;
	float fluid_density = 0.3;
	float p_bounciness = 0.9;
	int bounces_y;
	int bounces_x;
	ofVec2f reacting_force;
	ofVec2f drag(ofVec2f vector);
	void next_frame();
	void sum_vectors(ofVec2f ex_force, bool collision = false);

	Particle(int pos_x, int pos_y, int p_rad);
	void setup(int pos_x, int pos_y, int p_rad);
	void update();
	void draw();
	void set_bounciness(float i);
	void set_fluid_density(float i);
	void set_p_radius(int i);
	void reset_bounces();
	ofVec2f get_pos();
	int get_p_rad();
	void add_force(ofVec2f force);

	ofVec2f null_vector;

	void debug();


here’s some of the important methods

#include "Particle.h"

Particle::Particle() {


Particle::Particle(int pos_x, int pos_y, int p_rad) {

	position.set(pos_x, pos_y);
	p_radius = p_rad;
	null_vector.set(0, 0);

void Particle::setup(int pos_x, int pos_y, int p_rad) {

	position.set(pos_x, pos_y);
	p_radius = p_rad;
	null_vector.set(0, 0);

void Particle::update() {
	//acceleration.set(0, 0);

void Particle::draw() {

	ofDrawCircle(position.x, position.y, p_radius);

Help will be much appreciated, i’m still very much a beginner so any nudges in the right direction will help loads


for simplification you can consider ofFbo as a “canvas” you can draw things, and then draw the fbo (canvas) itself to the screen if desired. nothing more than that.

I suppose it has to be in your program, outside of the particle class, you can use allocate in your setup
and in your draw you can use like this:
// draw your particles here

Take a look at fboTrailsExample.
PS: you don’t even need an Fbo to test your particle system, if it works well without it then add it later.

1 Like

well, you are getting it wrong. It has nothing to do with a for loop or the framerate.

As @dimitre points out, it is just an offscreen canvas where you draw whatever you want, but not necesarily draw it to screen.
you can use it for a lot of useful things but for your particle system it will not bring any improvements, and if used the wrong way it might even be detrimental.

1 Like

thanks guys. I’m glad to know i dont have to rewrite everything, ill take another look at ofFbo when i start adding some trails.


1 Like

I thought there was a chapter about FBOs in the ofBook, but there is not. At least I did not find it.
So another way of thinking about an fbo is to consider it as a drawing surface, where you use the exact same commands as when you draw in the normal way, inside the draw function. The big difference is that the draw function erases everything you have drawn on each frame, at the frame rate that the app is running, in order to draw the next frame. On the contrary, you can keep what you have drawn into the FBO in memory as long as you want to, allowing you, for example, to keep the previously draw frame and make a trails effect. It is also useful when you have to render something that is expensive and there is no need to render on each frame but only when you have changed something. Or when using shaders and you want to pass the results of one shader into another one. Also it could be that you want to render something on screen multiple times at different positions so in order to make it more efficient you can render it once into the FBO and then draw it multiple times.
Does it make sense?
BTW, when I say render I mean calling a lot of draw functions, like ofDrawCircle(…) or drawing a mesh, etc. which can become very expensive when you add a lot of these. When I say draw I mean to put something on screen,


Awh @roymacdonald thanks dude. That’s cleared it up massively!

Yeah if it’s in the ofbook I haven’t found it! And theres not much out there!

Thanks again.

no prob.
FBOs (Frame Buffer Object) are not an openFrameworks exclusive feature, these are an openGL feature so you can find a lot of info if you just look for opengl fbo. although it can be a lot more complicated and technical, but the concept shall remain the same as in here Framebuffer Object - OpenGL Wiki

1 Like