FBO ? ofxFBOtexture ?

hi all …

well i’m trying to find out which could be the “best” FBO addon arround …
i’ve seen many different posts and files on gitHub but i’m not sure which one to take …

also i’ve read on some posts that OF team was thinking on adding FBO addon for next releases, with ping-pong rendering and some other cool FBO stuff …

could anybody point-me where to find & collaborate with this later FBOtexture addon ?
is there an open place for that or each user is doing it’s work on different files ?
maybe it’s all in gitHub, but as i’m not so used to it i can’t find which is the latest ofxFBOtexture repository …

thanks a lot :wink:


I was also confused by the may FBOs around, so I made my own very simple ofTextureFBO, based on ofTexture.

BUT… in the end, after running some tests, I found out that the fasted way to render to texture is to render to screen, then copy the screen to a texture, like this…

ofTexture texSolid  
	ofSetBackgroundAuto(false);		// erase manually  
	texSolid.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA);  
	// render your scene  
	texSolid.loadScreenData(0, 0, ofGetWidth(), ofGetHeight());  

hi rsodre !

well maybe i’m not understanding your code, but as long as i understand FBO’s, if you allocate a fbo and then at draw you activate it with fbo.begin() then draw your scene and then close it with fbo.close() … if you do that, the drawn scene is inside the texture related to the fbo, so then you can just drawit back to screen.

is this process that i’m describing slower then your code solution with .loadScreenData?

that’s awesome because basically FBOs are intended to be able to draw to textures straight away … amazing !¿

i’m still waiting to know where to find someone who is working with the ofxFBO to work as a ping-pong rendering … with 2 textures .

is anybody arround workin with this stuff ? or may just start from scratch ?
i was guessing to try to include this codes down here in a new ofxFBOPingPong ,


any thoughts ?

thanks !


FBO ping pong is around in openFrameworks, but it’s hard to find examples. If you look at the Reaction-Diffusion example in the Cinder ( http://libcinder.org/ ) framework, you’ll see working FBO ping pong code that is easy to port over.

hi LetsGoOutside

i’ve taken a look to RDifussion sample code in CinderLib …
and i’m confused right now …

as far as i can read the code of Cinder Application, seems like it’s using 2 FBO variables in order to run shader ping-pong loop …

gl::Fbo			mFBOs[2];  

	for( int i = 0; i < ITERATIONS; i++ ) {  
		mCurrentFBO = ( mCurrentFBO + 1 ) % 2;  
		mOtherFBO   = ( mCurrentFBO + 1 ) % 2;  
		mFBOs[ mCurrentFBO ].bindFramebuffer();  
		mFBOs[ mOtherFBO ].bindTexture();  
		gl::drawSolidRect( mFBOs[ mCurrentFBO ].getBounds() );  
		mFBOs[ mCurrentFBO ].unbindFramebuffer();  

this is confusing me a bit … because the method i read on here http://www.m3xbox.com/GPU-blog/?tag=ping-pong it’s just using just 1 FBO but with two textures binded to it …

first i developped a first intuitive release in a similar way to the one in CinderLib example. I’ve test it and it runs ok … but i think that the solution with just 1 FBO it’s more elegant and even maybe much faster because you just play the ping-pong of textures inside the FBO, without changing GL context or unbinding continously FBOs …

any ideas on whic solution is more appropiate ?


It’s a common misconception that you have to have a Texture with each FBO. As the example you found shows, this is not the case. You can just change out the particular texture attached to the FBO. Textures own the buffer of pixels you’re drawing to. FBOs own other things normally associated with a rendering surface like how many draw buffers are enabled, if there are depth or stencil buffer attached. An FBO is an empty vessel for Textures. The caveat is that you can’t attach Textures with different dimensions and formats to the same FBO.

According to Zach, one of the most recent versions of ofxFBOTexture is available in Damian’s git repo:


hi Kyle !

thanks for pointing this out … i’ve already been using Damian’s ofxFBOtexture as a base to extend it to be able to work as a “ping-pong” FBO.

do you have any idea or knowledge on how to make it work ?
i’ve been trying to merge into ofxFBOtexture the code i found here :


but still i’m not getting the expected results …

my idea is to be able to implement a kind of ofxFBOPingPongTexture.
as ofxFBO extends a ofTexture i’ve added 2 ofTexture’s into the ofxFBOTexture to work as a ping-pong rendering color attachment’s. I’m sure that it’s possible to do it adding just one ofTexture (as ofxFBO is already a ofTexture) but i found more easy to develop it with 2 diferent ofTexture’s for the ping pong thing …

i’m willing to use it as a ping-pong for iterative shader applications but also for chaining different shader programms into a same texture … i think this is also possible with a ping-pong structure ? is it ?

what i’m doing is a process like …

in setup


in draw

// applies the color attachment's to the needed texture ...   
... render stuff with shader 1  
// swaps fbo color attachments  
// applies the color attachment's to the needed texture ...   
... render stuff with shader 2  

i’m finding problems to make it work, but i’m still trying to figure out if the code from GPUterrain’s blog is appliable into this subject …

anybody has tried implementing ofxFBOtexture with ping-pong rendering ?
when i’ll be back at home i’ll post what i got until now … to see if someone’s can help …


Hey eloi, I have’t done FBO ping pong before. But check out Theo’s post here:


I know he was using some ping pong techniques for that.

hola kyle :wink:

thanks for theo’s shaders link. i’ve taken a look at them and he’s using 2 FBO’s for making the ping-pong, the same as i already have.

my goal is to be able to do ping-pong rendering with just one FBO and 2 textures linked to them , so make the ping-pong “inside” the FBO (diferent then Theo’s work where he’s ping-ponging 2 FBO’s) .

i’ve read that without swapping FBO contexts it’s faster, but already FBO is maybe fast enough i was just curious to make it work as it’ seems me more powerfull in compositing stuff …

thanks for the help …


Hi, yup an FBO can contain more than one texture. Currently ofxFBOTexture is not designed that way though so it’s not possible without some serious mods to it though I’m afraid.

An FBO is not a texture, it has a texture (or more than one). So an ideal FBO wrapper would not extend ofTexture, but instead would contain a variable number of textures.

You can find an easy to follow tutorial here on multiple textures bound to an FBO here

hi memo

thanks for the link ! i’ll take a look to it and see if i can make it work somehow …

i agree with u that ofxFBOtexture should not extend ofTexture, but contain several textures .

i’ll try to make it work … if anyone is interested on it we can try to work it out together …


Just to complicate things even more, here’s the FBO class I’m using at the moment.

It supports multiple texture attachments up to the maximum defined, and can be used for Multiple Render Targets in conjunction with shaders (see something like this: http://www.gamedev.net/reference/articl-…-le2333.asp)

I’m using it like this:

ofxFrameBuffer gbuffer;  
// Setup the multi-texture FBO, with depth render buffer  
gbuffer.setup(AppWidth, AppHeight);  
// Rendering to the G-Buffer  
// draw some stuff into the buffer, write to the textures using gl_FragData[]  
// Now use the multiple textures in another shader  

You can also copy (blit) to other FBOs like this:

	gbuffer.blitTo(&sceneFBO, GL_DEPTH_BUFFER_BIT);  



wow that looks great. is it on github or anywhere? The order order that you attach the textures, is that important? Is that the index you give when binding? If so, can I make a suggestion to perhaps using an stl::map for the textures, so when you attach, you can optionally give a name, and then bind by name too (if you omit the name when creating, it defaults to using sequential numbers so you currently have it). just a though…

It’s a modified (OF friendly version) of some FBO code I found somewhere and it seems to do everything I want.

Yes the order of attachment is important…this decides the indexes of the textures. I guess a map could be useful to make this more descriptive.

I haven’t hosted this anywhere, I just started using it recently…


grimus … well i’ve tried to use your code and sincerly could not make it to work properly .
but when looking at it i asked myself if MRT that you implemented is usefull for my purpose, where i want to work inside an fbo to render several times to 2 textures, swapping at each step the textures as input and output for a shader … as example : effecting a videoplayer texture with 2 diferent chained shaders inside just one FBO … mmm … can i do that with your addon ?

do i get to explain ? english is not my best language …

any example on how to use it ?

i’m just a bit confussed as i’m not good at this level of OpenGL FBO stuff … sorry … i’m slowly getting into this nightmare technique …


Well MRT just means using a shader to render to multiple textures in different ways.

I’m not entirely clear what you want to do but I undertand it as something like this:

myFBOshader.setUniform(“Tex0”, 0);
myFBOshader.setUniform(“Tex1”, 1);
// shader renders to texture 1 using texture 1 as input

(next frame)

myFBOshader.setUniform(“Tex0”, 1);
myFBOshader.setUniform(“Tex1”, 0);
// shader render to texture 0 using texture 1 as input

Tex) and Tex1 are the Sampler2D uniforms you use to access the textures. So you modify the uniforms to point to alternating textures. You would also use glFragData[] to write to the appropriate texture.

To further complicate (maybe simplify) things, I just wrote http://forum.openframeworks.cc/t/blending-multiple-fbos-with-a-shader/4302/6. It plays nicely with ofxShader, but doesn’t allow for rendering to multiple textures simultaneously (though that could be done easily).

The primary difference between it and every other FBO wrapper I’ve seen is that it doesn’t store textures internally. It assumes you create textures separately (using ofImage, for example) and then you call setTarget() to attach it to the color buffer. Right now it automatically detaches any other textures from the color buffer.

I think this style of FBO usage could be really helpful in the future, because it takes advantage of the code already written in ofTexture.

hy kyle and grimus !

kyle your approach sounds like is where i’m going to …
i’ve made some testing and i’m able to switch input and output textures for the FBO on the fly … adding your setTarget stuff will make it even more powerfull so it becomes easy to get any ofTexture already running in OF … good !!

today i’m out for holydays … i’ll be back soon and try it with your ofxFBO kyle !

thanks all for the answers … i’m pretty sure we’re getting where i wanted !!
once is done and running i’ll post my results as it’s a good workflow for blending textures inside an FBO + shaders … YEAH !!


Hey Kyle,

I’ve been using your ofxFbo class and it’s working well - I like the idea of keeping the textures outside of the class. I’m running into a problem where any text that I draw using ofDrawBitmapString() is rendered upside down (though in the proper position). Everything else is rendering fine. Any ideas?

void testApp::setup()  
    ofSetFrameRate( 60 );  
    fboTexture.allocate( 1024, 1024, GL_RGB );  
    fbo.setup( 1024, 1024 );  
    fbo.attach( fboTexture );  
void testApp::draw()  
    string info = "FPS: " + ofToString( ofGetFrameRate()) + ", noiseLevel:";  
    ofSetColor( 255, 255, 255 );  
    ofDrawBitmapString( info, 80, 80 );  
    fbo.draw(0, 0);  

Grimus - I tried giving your class a go since I’m working on shaders with multi-texturing, though I couldn’t get it to compile for some reason. Seems that some of the opengl defines (mainly the ones relating to stencils) are not recognized. I’m on windows + codeblocks. Any ideas?

This is what I’m getting:
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp:59: error: ‘GL_DEPTH24_STENCIL8’ was not declared in this scope
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp:59: error: ‘GL_DEPTH_STENCIL’ was not declared in this scope
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp:60: error: ‘GL_DEPTH_STENCIL_ATTACHMENT’ was not declared in this scope
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp:72: error: ‘GL_DEPTH_STENCIL_ATTACHMENT’ was not declared in this scope
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp: In member function ‘void ofxFrameBuffer::attachTexture(GLenum, GLint)’:
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp:142: error: ‘GL_DEPTH24_STENCIL8’ was not declared in this scope
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp:142: error: ‘GL_DEPTH_STENCIL’ was not declared in this scope
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp:144: error: ‘GL_UNSIGNED_INT_24_8’ was not declared in this scope
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp:145: error: ‘GL_DEPTH_STENCIL_ATTACHMENT’ was not declared in this scope
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp:158: error: ‘GL_DEPTH_STENCIL’ was not declared in this scope
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp:159: error: ‘GL_DEPTH_ATTACHMENT’ was not declared in this scope
C:\Users\james\Desktop\Development\of_preRelease_v0061_win_cb_FAT\addons\ofxFrameBuffer\src\ofxFrameBuffer.cpp:160: error: ‘GL_STENCIL_ATTACHMENT’ was not declared in this scope