Using ofTranslate with fbo.draw()

hi ! completely new here but something has been buggin me for a few hours,
I must be missing something but I can never get my fbo to take the whole screen space when I translate everything using ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2)

Here is my setup code

	fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA);
	fbo.begin();
	ofClear(255);
	fbo.end();

Here is my draw code

ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);
fbo.draw(0, 0);
fbo.begin();
diffline.draw();
fbo.end();

my diffline.draw() draws a circle in the center (0,0) of the screen, but using this code, only the bottom left corner of the circle is drawn

thanks !

It looks like you are translating the fbo itself and then drawing the circle centered at (0,0) inside the fbo rather than translating the circle inside the fbo. :slight_smile:

I like to update the fbo (fbo.begin()/fbo.end() block) in update() instead of draw().

That would look like this:

update():

fbo.begin();
ofSetColor(255, 0, 0); 
ofTranslate(fbo.getWidth() / 2, fbo.getHeight() / 2);
ofDrawCircle(0, 0, 100);
fbo.end();

draw():

fbo.draw(0,0);

In this case, you could achieve the same thing by putting the same lines in draw but be careful about drawing the fbo before you update it, won’t make a difference in this case but it seems like something that could lead to strange behavior in certain cases.

I hope that helps. Let me know if you still have trouble.

Take care!

thanks a lot for the quick reply ! :slight_smile:
I’ll try this asap but it makes complete sense, thx for the update tip too !

1 Like