Book Image

Kivy Cookbook

By : Hugo Solis
Book Image

Kivy Cookbook

By: Hugo Solis

Overview of this book

Table of Contents (16 chapters)
Kivy Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Rendering in a Framebuffer


The Framebuffer represents a helpful tool for the graphical content of Kivy. It is an offscreen tool where we can draw any complex set of instructions. We render this offscreen tool and use it on the canvas as a whole.

Getting ready

You need to have cleared the recipes in Chapter 5, Graphics – Canvas and Instructions, to understand this recipe because you need to be able to differentiate between the Framebuffer and the canvas.

How to do it…

To complete this recipe, we will use just one Python file that has four rectangles with a texture that we are going to create in the Framebuffer. Follow these steps:

  1. In the Python file, import the usual Kivy packages.

  2. Also import the Fbo package.

  3. Define the MyW class.

  4. Define the __init()__ method for the class.

  5. Provide canvas in the method.

  6. Create the fbo context.

  7. Define four rectangles using the fbo texture.

  8. Define the fbo context.

  9. Then, define two rectangles of different colors:

    import kivy
    kivy.require('1.9.0') # Code tested in this version...