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 …
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…
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 ,
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.
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 …
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.
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
fboPingPong.allocate(...);
in draw
fboPingPong.begin()
// applies the color attachment's to the needed texture ...
fboPingPong.renderPingPong()
shader1.setActive(true);
... render stuff with shader 1
// swaps fbo color attachments
fboPingPong.swapPingPong()
// applies the color attachment's to the needed texture ...
fboPingPong.renderPingPong()
shader2.setActive(true);
... 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 …
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 …
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.
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);
gbuffer.attachRenderBuffer(GL_DEPTH_COMPONENT24);
gbuffer.attachTexture(GL_RGBA8);
gbuffer.attachTexture(GL_RGBA8);
gbuffer.attachTexture(GL_RGBA16F_ARB);
...
// Rendering to the G-Buffer
gbuffer.startRender();
// draw some stuff into the buffer, write to the textures using gl_FragData[]
...
// Now use the multiple textures in another shader
glActiveTexture(GL_TEXTURE0);
gbuffer.bindTexture(0);
glActiveTexture(GL_TEXTURE1);
gbuffer.bindTexture(1);
glActiveTexture(GL_TEXTURE2);
gbuffer.bindTexture(2);
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…
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.setShaderActive(true);
myFBO.bindTexture(0);
myFBOshader.setUniform(“Tex0”, 0);
myFBOshader.setUniform(“Tex1”, 1);
// shader renders to texture 1 using texture 1 as input
(next frame)
myFBO.bindTexture(1);
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.
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.
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 !!
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?
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