Python Kivy graphics library for OpenGLES 2 working


14 posts
by chrislale » Sun Jun 17, 2012 7:21 pm
Kivy (http://kivy.org/ is working on my RPi, but it's very slow. Any suggestions for a way forward would be very welcome.

I used a raspbian pisces R2 wheezy image (http://www.raspbian.org/PiscesImages) apt-get updated and upgraded. I installed the packages required following the installation instructions for Ubuntu at http://kivy.org/docs/installation/installation.html. I installed the development version (1.3.0) from github. Then I modified the setup.py file so that it would find the Broadcom files in /opt/vc before looking in /usr. Eg replacing lines such as
Code: Select all
default_header_dirs = ['/usr/include', '/usr/local/include']

with
Code: Select all
default_header_dirs = ['/opt/vc/include', '/usr/include', '/usr/local/include']

I then compiled and installed Kivy using checkinstall to make removal easier and cleaner
Code: Select all
checkinstall python setup.py install

This simple Hello World runs from a terminal window in X:
Code: Select all
from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
    def build(self):
        return Button(text='Hello World')

TestApp().run()

The full-window button turns blue a full second after the mouse click.

Is this an issue with X, the drivers, my approach or have I missed something? At least it seems possible that Python Kivy will be usable eventually.
Chris Lale
Posts: 4
Joined: Wed Dec 14, 2011 9:03 am
by JF002 » Wed Jan 09, 2013 10:32 pm
Hi!

I discovered Kivy today and I would like to try it on my Raspi.

I followed the instructions in the installation manual and your instructions. During the installation, it told me that OpenGL ES headers were found.
But when running a script from X, it tell me that no GLX display is available, tries to fallback to SDL but it fails too.
When running from console, it tells me that OpenGL is not available.

Can you give me more complete instructions? Did you do any other modification in setup.py file, or in another file?

By the way, did you find any way to improve performances?

Thanks for your help!
My blog [FR] : http://blog.slashome.fr.cr
Posts: 80
Joined: Sat Feb 04, 2012 8:49 am
by JF002 » Thu Jan 10, 2013 8:13 pm
If I understand correctly, Kivy is based on pygame which is based on SDL.
I made some test with SDL, and I onmy manage to create a SWSURFACE, not a HWSURFACE or DOUBLEBUFFER.

I'm totally confused about GPU acceleration, OpenGL, OpenGL ES,... support on RaspberryPi...

It seems that Raspi should support OpenGL ES and Kivy uses OpenGL ES... I don't understand.

I fact... I was asking the same kind of questions about QT5 and GPU acceleration support, but found nothing revelant up to now...

And I'm still not able to run a Kivy app... Here is the complete error message when run from X :

Code: Select all
pi@raspberrypi ~ $ python test.py
[INFO   ] Kivy v1.5.2-dev
[INFO   ] [Logger      ] Record log in /home/pi/.kivy/logs/kivy_13-01-10_5.txt
[INFO   ] [Factory     ] 137 symbols loaded
[DEBUG  ] [Cache       ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG  ] [Cache       ] register <kv.image> with limit=None, timeout=60s
[DEBUG  ] [Cache       ] register <kv.atlas> with limit=None, timeout=Nones
[INFO   ] [Image       ] Providers: img_dds, img_pygame, img_gif (img_pil ignored)
[DEBUG  ] [Cache       ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG  ] [Cache       ] register <kv.shader> with limit=1000, timeout=3600s
[INFO   ] [Text        ] Provider: pygame
[DEBUG  ] [App         ] Loading kv <./test.kv>
[DEBUG  ] [App         ] kv <./test.kv> not found
[INFO   ] [Window      ] Provider: pygame
[WARNING] [WinPygame   ] Video: failed (multisamples=2)
[WARNING] [WinPygame   ] trying without antialiasing
[ERROR  ] [Window      ] Unable to use pygame
[ERROR  ] [Window      ] The module raised an important error: "Couldn't find matching GLX visual"
 Exception kivy.core.CoreCriticalException: CoreCriticalException("Couldn't find matching GLX visual",) in 'kivy.properties.dpi2px' ignored
[INFO   ] [Window      ] Provider: pygame
[WARNING] [WinPygame   ] SDL wrapper failed to import!
[DEBUG  ] [Window      ] Ignored <sdl> (import error)
[DEBUG  ] [Window      ] Ignored <x11> (import error)
[CRITICAL] [Window      ] Unable to find any valuable Window provider at all!
[CRITICAL] [App         ] Unable to get a Window, abort.


Any idea?
My blog [FR] : http://blog.slashome.fr.cr
Posts: 80
Joined: Sat Feb 04, 2012 8:49 am
by paddyg » Thu Jan 10, 2013 11:38 pm
Feel free to look through the stuff we've been doing on pi3d/integration. A couple of weeks ago the ES 2 version of the demos was often running a bit slower than the v1 but it's now well ahead.
- A large part of the increase in speed came from working over the shaders. I basically split them up so each shader served one purpose and got rid of pretty much every 'if' statement. I also moved as much as possible out of the fragment shader into the vertex shader and as much as possible out of the shaders into python, which required..
- Getting all the matrix work done by numpy and putting flags so it only needed to be done if something had moved and
- Transferring all the uniform variables as one or two long arrays

Some of this might be getting deeper into the nuts and bolts than you want but you might have to do that to get the speed. (Or you could use pi3d I suppose! Any help with the project gratefully accepted)
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d
User avatar
Posts: 876
Joined: Sat Jan 28, 2012 11:57 am
Location: Bingley, Yorkshire
by JF002 » Fri Jan 11, 2013 4:00 pm
Is Pi3D related to Kivy?
I'll have a look anyway!

Basically, I'm searching for a UI framework that would allow me to create "modern" (adapted to mobile/touchscreen world) and fast, fluid GUI.
So any suggestion is welcome!
My blog [FR] : http://blog.slashome.fr.cr
Posts: 80
Joined: Sat Feb 04, 2012 8:49 am
by ghans » Fri Jan 11, 2013 5:14 pm
Linux and X11 are not designed for touch AFAIK.
SurfaceFlinger is , but Android has no hardware-acceleration
till date and is very slow.

So your best bet would be Qt and C\C++ , bexause that has
been proven to work on the Pi. (i.e. BerryBoot is also a Qt app).
Perhaps JogAMP NEWT (Java) might also be a option.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
Posts: 4536
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany
by JF002 » Fri Jan 11, 2013 5:52 pm
I tried to install/build/cross-compile/... QT5 (which seems to provide what I need) with no results :(
And I still don't know if GPU acceleration works with QT5 on the Rpi.

Perhaps I should investigate a little more...

When I found Kivy, I tought it could be what I need, but lighter than QT. And since I want to learn Python, that could have been the right choice.
My blog [FR] : http://blog.slashome.fr.cr
Posts: 80
Joined: Sat Feb 04, 2012 8:49 am
by -rst- » Sat Jan 12, 2013 7:07 pm
The problem you are having with Kivy seems to be that it does not recognise the 'windowing' libraries available on RPi correctly: there is no GLX at all on RPi - instead EGL should be used... Not sure why there is an issue using SDL as some other SDL apps seem to run.
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
Posts: 900
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland
by -rst- » Fri Jan 25, 2013 11:33 am
Had a bit more in depth look at Kivy - just in case someone else is interested...

It seems Kivy relies on Pygame for windowing and Pygame in turn relies on SDL, so it looks like it is down to SDL to play nice with the RPi graphics 'sub-systems'.

http://kivy.org/docs/guide/architecture.html

The installation docs seem to include Mesa drivers/libraries as dependencies and afaik this would imply non-accelerated graphics?

http://kivy.org/docs/installation/insta ... linux.html

Maybe it would be possible to configure Kivy to use the correct libraries ...wonder if Vanfanel's dispmanx-SDL would work with this if wanting to run outside X...
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
Posts: 900
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland
by topguy » Fri Jan 25, 2013 12:01 pm
JF002 wrote:I tried to install/build/cross-compile/... QT5 (which seems to provide what I need) with no results :(
And I still don't know if GPU acceleration works with QT5 on the Rpi.

Perhaps I should investigate a little more...

When I found Kivy, I tought it could be what I need, but lighter than QT. And since I want to learn Python, that could have been the right choice.


Qt5 is OpenGLES accelerated on the RasPi. Search youtube and you will find some examples.
I'm experimenting with QtQuick (QML) mostly. And I'm either using the raspbian packages from http://twolife.be/raspbian or the complete image made from the tools at http://www.bsquask.com/

But Kivy looks interesting also if one can get it to only do OpenGLES.
User avatar
Posts: 668
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway
by JF002 » Sat Jan 26, 2013 4:09 pm
topguy wrote:But Kivy looks interesting also if one can get it to only do OpenGLES.


I worked on that these last days, and manage to add what was missing to Kivy in order to load OpenGL ES libraries from RaspberryPI. I'm able to run all the examples from the kivy sources.

It's not complete, though, because only the drawing is working... I have no window management, no event from keyboard, mouse and touchscreen, but it is a good start.

Here are some pictures:
https://docs.google.com/file/d/0B17J_Rv ... R2YjA/edit
https://docs.google.com/file/d/0B17J_Rv ... FFUm8/edit
https://docs.google.com/file/d/0B17J_Rv ... kyX1k/edit
https://docs.google.com/file/d/0B17J_Rv ... RnZUU/edit

I'll try to continue my work and keep you up to date.
My blog [FR] : http://blog.slashome.fr.cr
Posts: 80
Joined: Sat Feb 04, 2012 8:49 am
by prussia » Fri Mar 01, 2013 8:06 pm
Hi,
Did you manage to get any further in the kivy install ? I'm stuck with this error:
Code: Select all
In file included from /tmp/easy_install-x8qCB8/Kivy-1.5.1/kivy/graphics/texture.c:254:0:
/tmp/easy_install-x8qCB8/Kivy-1.5.1/kivy/graphics/gl_redirect.h:38:22: fatal error: GL/gl.h: No such file or directory
compilation terminated.
 error: Setup script exited with error: command 'gcc' failed with exit status 1


I can't seem to get past that. Which exact instructions did you use? I'm using adafruits install os.
Posts: 29
Joined: Sun Jan 13, 2013 12:03 am
by -rst- » Sat Mar 02, 2013 7:41 pm
Looks like the configure script (usually there is one) doe not regocnise the platform and tries to build against OpenGL and not OpenGL ES - afaik, it should be looking for gles.h...
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'
Posts: 900
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland
by mrtroback » Sat Mar 02, 2013 10:49 pm
Hi,

Just so you know there is currently an ongoing crowdfund project subjecting Kivy on the Raspberry Pi: https://www.bountysource.com/#fundraise ... spberry-pi
Posts: 4
Joined: Fri Jul 06, 2012 2:06 pm