Skip to Content
Kivy Cookbook
book

Kivy Cookbook

by Hugo Solis
August 2015
Intermediate to advanced
246 pages
4h 21m
English
Packt Publishing
Content preview from Kivy Cookbook

Creating your own shader

We have already worked with shaders in this chapter, but now we will work with our own shaders. To show this, we will create an app with only the ShaderWidget.

Getting ready

We will use the preceding recipe Editing shaders to complete this recipe. Particularly, we will use the ShaderWidget class implemented there.

How to do it…

We will need a KV file and a Python file in this recipe. The KV file gives the size and position to the ShaderWidget, and the Python file will have our shader. Now, follow these steps:

  1. In the KV file, define the ShaderWidget rule.
  2. Add canvas for color, pos, and size:
    <ShaderWidget>:
    canvas:
        Color:
            rgb: 1, 0, 0
        Rectangle:
            pos: self.pos
            size: self.size
  3. In the Python file, import the usual Kivy packages.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Creating Apps in Kivy

Creating Apps in Kivy

Dusty Phillips
Kivy Blueprints

Kivy Blueprints

Mark Vasilkov

Publisher Resources

ISBN: 9781783987382Supplemental Content