Framebuffer — Kivy v1.0.1-dev documentation

# Framebuffer

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.

class `kivy.graphics.fbo.` `Fbo`(*args, **kwargs)

  Bases: `kivy.graphics.instructions.RenderContext`

  Fbo class for wrapping the OpenGL Framebuffer extension. The Fbo support “with” statement.

  Parameters : | clear_color: tuple, default to (0, 0, 0, 0) Define the default color for clearing the framebuffer size: tuple, default to (1024, 1024) Default size of the framebuffer push_viewport: bool, default to True If True, the OpenGL viewport will be set to the framebuffer size, and will be automatically restored when the framebuffer released. with_depthbuffer: bool, default to True If True, the framebuffer will be allocated with a Z buffer. texture: `Texture`, default to None If None, a default texture will be created.

  `bind`()
    Bind the FBO to the current opengl context.

      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_buffer`()

    Clear the framebuffer with the `clear_color`

  `clear_color`

    Clear color in (red, green, blue, alpha) format.

  `release`()

    Release the Framebuffer (unbind).

  `size`

    Size of the framebuffer, in (width, height) format.

    If you change the size, the framebuffer content will be lost.

  `texture`

    Return the framebuffer texture

class `kivy.graphics.fbo.` `FboException`

  Bases: `exceptions.Exception`

  FboException is fired when an FBO error happen during creation or usage.

  `resolve_status`()

    FboException.resolve_status(self, status)