Fbo is like an offscreen window. You can activate the fbo for rendering into a texture, and use your fbo as a texture for another drawing.
Fbo act as a kivy.graphics.instructions.Canvas.
Exemple of using an fbo for some color rectangles
from kivy.graphics import Fbo, Color, Rectangle
class FboTest(Widget):
def __init__(self, **kwargs):
super(FboTest, self).__init__(**kwargs)
# first step is to create the fbo and use the fbo texture on other
# rectangle
with self.canvas:
# create the fbo
self.fbo = Fbo(size=(256, 256))
# show our fbo on the widget in different size
Color(1, 1, 1)
Rectangle(size=(32, 32), texture=self.fbo.texture)
Rectangle(pos=(32, 0), size=(64, 64), texture=self.fbo.texture)
Rectangle(pos=(96, 0), size=(128, 128), texture=self.fbo.texture)
# in the second step, you can draw whatever you want on the fbo
with self.fbo:
Color(1, 0, 0, .8)
Rectangle(size=(256, 64))
Color(0, 1, 0, .8)
Rectangle(size=(64, 256))
If you change anything in the self.fbo object, it will be automaticly updated, and canvas where the fbo is putted will be automaticly updated too.
Bases: kivy.graphics.instructions.RenderContext
Fbo class for wrapping the OpenGL Framebuffer extension. The Fbo support “with” statement.
Parameters : |
|
---|
Bind mean that you enable the Framebuffer, and all the drawing operations will act inside the Framebuffer, until release() is called.
The bind/release operation are automatically done when you add graphics object in it. But if you want to manipulate a Framebuffer yourself, you can use it like this:
self.fbo = FBO()
self.fbo.bind()
# do any drawing command
self.fbo.unbind()
# then, your fbo texture is available at
print self.fbo.texture
Clear the framebuffer with the clear_color
Clear color in (red, green, blue, alpha) format.
Release the Framebuffer (unbind).
Size of the framebuffer, in (width, height) format.
If you change the size, the framebuffer content will be lost.
Return the framebuffer texture
Bases: exceptions.Exception
FboException is fired when an FBO error happen during creation or usage.
FboException.resolve_status(self, status)