- english
- /
- japanese
methods
- activateAllDrawBuffers()
- allocate()
- begin()
- bind()
- checkGLSupport()
- draw()
- end()
- getDefaultTextureIndex()
- getDepthBuffer()
- getDepthTexture()
- getFbo()
- getHeight()
- getNumTextures()
- getStencilBuffer()
- getTextureReference()
- getWidth()
- isAllocated()
- maxColorAttachments()
- maxDrawBuffers()
- maxSamples()
- operator=()
- readToPixels()
- resetAnchor()
- setActiveDrawBuffer()
- setActiveDrawBuffers()
- setAnchorPercent()
- setAnchorPoint()
- setDefaultTextureIndex()
- setUseTexture()
- unbind()
As an example, with an fbo you can do some drawing to the fbo (instead of to the screen or a texture) and then do some blurring, maybe invert the colors, combine multiple images, all without needing to draw it to the screen until you're ready. fbos are also used to create views of other scenes, like a TV in a house. A scene can be rendered through an FBO to a texture, then that texture can be applied to the surface of another object. You can also create a depth buffer within your fbo to figure out which objects should go in front of which other objects. As an example of an advanced usage: Create an ofFbo. Attach the color buffer of the ofFbo to a texture. Attach the depth buffer of the ofFbo to a texture. Render the texture to screen with a pixel shader using ofShader. Rad! The following code snippet shows ping-ponging, a common technique with FBOs that involves adding two textures to the FBO and blurring one then the other in succession to create a blur effect.
// draw scene into fbo
fbo.begin();
vidGrabber.draw(0, 0, fbo.getWidth(), fbo.getHeight());
fbo.end();
// ping pong between two attachments using shader
fbo.begin();
shader.begin();
// the fbo contains two textures, so we blur one
// then copy it to the other and repeat 8 times
for(int i=0; i<8; i++) {
int srcPos = i % 2; // attachment to write to
int dstPos = 1 - srcPos; // attachment to read from
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + dstPos); // write to this texture
ofClear(0, 0, 0, 0);
shader.setUniform1i("tex0", 0);
shader.setUniform1f("sampleOffset", i*2+1);
fbo.getTextureReference(srcPos).draw(0, 0);
}
shader.end();
fbo.end();
fbo.draw(0, 0);
Bloom effects are also often done with FBO objects using Multiple Render to Texture or MRT effects.
allocate(...)
void ofFbo::allocate(int width, int height, int internalformat=GL_RGBA, int numSamples=0)
Before you use the fbo you need to allocate it. This sets the width, height, and GL type of the fbo (i.e. whether it has alpha data or not) and the number of samples for MSAA. MSAA is sort of a big topic. MSAA is what you typically have in hardware on a modern graphics card. The graphics card renders to a surface that is larger than the final image, but in shading each "cluster" of samples (that will end up in a single pixel on the final screen) the pixel shader is run only once. We save a ton of fill rate, but we still burn memory bandwidth. This technique does not anti-alias any effects coming out of the shader, because the shader runs at 1x, so alpha cutouts are jagged. This is the most common way to run a forward-rendering game. MSAA does not work for a deferred renderer because lighting decisions are made after the MSAA is "resolved" (down-sized) to its final image size.
allocate(...)
void ofFbo::allocate(Settings settings=Settings())
You can also allocate the ofFbo using a Settings object
begin()
void ofFbo::begin()
Any drawing that you do after begin() is drawn into the fbo rather than the screen. This is how you draw things into your ofFbo instance.
bind()
void ofFbo::bind()
This lets you draw the fbo using vertices to define the area that the fbo will be drawn into. This can be an ofRectangle, ofMesh, or other vertex based drawing technique.
checkGLSupport()
bool ofFbo::checkGLSupport()
This allows you quickly check whether your graphics card supports FBO objects.
draw(...)
void ofFbo::draw(float x, float y)
This allows you draw everything that's in your fbo to the screen using its default height and width at the x, y indicated.
draw(...)
void ofFbo::draw(float x, float y, float width, float height)
This allows you draw everything that's in your fbo to the screen using any height and width. Any stretching is up to you to handle appropriately.
end()
void ofFbo::end()
Any drawing that you do after end() is drawn into the fbo rather than the screen. This is how you stop drawing things into your ofFbo instance.
getDefaultTextureIndex()
int ofFbo::getDefaultTextureIndex()
If you've set the default texture reference, you can get access to it here.
getDepthBuffer()
GLuint ofFbo::getDepthBuffer()
This gives you the OpenGL id of the depthBuffer that the fbo contains.
getFbo()
GLuint ofFbo::getFbo()
This returnes the GLuint of Fbo for advanced actions, if you're interested in doing something with the FBO id directly.
getHeight()
float ofFbo::getHeight()
This returns the height of the fbo. This is just like height of a texture: it sets how many pixels wide the allocated memory on the graphics card is.
getNumTextures()
int ofFbo::getNumTextures()
This returns the number of textures that the fbo contains.
getStencilBuffer()
GLuint ofFbo::getStencilBuffer()
This gives you the OpenGL id of the depthBuffer that the fbo contains.
getTextureReference()
ofTexture ofFbo::getTextureReference()
This gives you access to the ofTexture contained w/in the fbo. This returns the texture index returned by setDefaultTextureIndex() if you've set it there.
getTextureReference(...)
ofTexture ofFbo::getTextureReference(int attachmentPoint)
This gives you access to a particular ofTexture if there are more than 1 contained w/in the fbo.
getWidth()
float ofFbo::getWidth()
This returns the width of the fbo that was set when it was allocated. This is just like width of a texture: it sets how many pixels wide the allocated memory on the graphics card is.
maxColorAttachments()
int ofFbo::maxColorAttachments()
This returnes the max number of simultaneous max color attachments, i.e. textures that will just be used for color information.
maxDrawBuffers()
int ofFbo::maxDrawBuffers()
This returnes the max number of simultaneous draw buffers that your graphics card supports, i.e. color buffers that can be drawn to simultaneously. This is usually 4 at present.
maxSamples()
int ofFbo::maxSamples()
This is the maximum number of MSAA samples that your graphic card supports.
operator=(...)
ofFbo ofFbo::operator=(const ofFbo &fbo)
This overloaded operator allows you to set one fbo from another using the = operator. Very convenient.
readToPixels(...)
void ofFbo::readToPixels(ofPixels &pixels, int attachmentPoint=0)
This allows you to get the pixels from an ofFbo and store it in an ofPixels instance. The attachmentPoint parameter allows you indicate which of the textures attached to the fbo you want to grab
readToPixels(...)
void ofFbo::readToPixels(ofShortPixels &pixels, int attachmentPoint=0)
This allows you to get the pixels from an ofFbo and store it in an ofShortPixels instance. The attachmentPoint parameter allows you indicate which of the textures attached to the fbo you want to grab. The ofShortPixels instance is useful when you want your image at short ints, or non-floating point values.
readToPixels(...)
void ofFbo::readToPixels(ofFloatPixels &pixels, int attachmentPoint=0)
This allows you to get the pixels from an ofFbo and store it in an ofShortPixels instance. The attachmentPoint parameter allows you indicate which of the textures attached to the fbo you want to grab. The ofShortPixels instance is useful when you want your image as floating point values.
setAnchorPercent(...)
void ofFbo::setAnchorPercent(float xPct, float yPct)
You can set the anchor position that the texture will be drawn at. This means that passing 0.5, 0.5 will draw the ofFbo center at the point you pass in to the draw() method.
setAnchorPoint(...)
void ofFbo::setAnchorPoint(float x, float y)
This allows you set the anchor position of the texture in the fbo when you draw it.
setDefaultTextureIndex(...)
void ofFbo::setDefaultTextureIndex(int defaultTexture)
This allows you set the default texture that your fbo will use. If you're using multiple textures, this will return the one that should be draw to, scaled, and positioned.
Last updated
Thursday, 16 May 2013 14:01:00 UTC
-
cbf0910627a25e6153f2452833c5313fe6067059

