Difference between revisions of "EBC Exercise 33 pygame"
m (Fixed formatting) |
m (typo) |
||
Line 11: | Line 11: | ||
From: [https://askubuntu.com/questions/97717/how-can-i-get-pygame-for-python3 https://askubuntu.com/questions/97717/how-can-i-get-pygame-for-python3] | From: [https://askubuntu.com/questions/97717/how-can-i-get-pygame-for-python3 https://askubuntu.com/questions/97717/how-can-i-get-pygame-for-python3] | ||
− | Note: Create a new folder to put installation | + | Note: Create a new folder to put installation in |
bone$ '''sudo apt-get install mercurial python3-dev python3-numpy libav-tools libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev''' | bone$ '''sudo apt-get install mercurial python3-dev python3-numpy libav-tools libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev''' |
Revision as of 10:07, 10 October 2017
Embedded Linux Class by Mark A. Yoder
Pygame is a framework that can be used to create games, graphics, and more within python. It has the ability to draw sprites, primitives, and handle multiple surfaces. The back end conveniently can work on multiple platforms, but most importantly it can write directly to frame buffers. This has the benefit for ECE497 of being able to control the small SPI LCDs cleanly, without worrying about writing to memory locations directly and developing custom graphics libraries.
Unfortunately, pygame does not come installed for python3. It works great with python 2.7, but no pre-built packages are availible for python3. This raises an issue when python3 is required, such as when rcpy is to be used to read from encoders, drive servos, etc.
To solve this problem, the below shows a method that worked for me to get pygame built and installed.
Installing pygame for python3
From: https://askubuntu.com/questions/97717/how-can-i-get-pygame-for-python3
Note: Create a new folder to put installation in
bone$ sudo apt-get install mercurial python3-dev python3-numpy libav-tools libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev bone$ sudo apt-get install libsmpeg-dev libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev bone$ hg clone https://bitbucket.org/pygame/pygame bone$ cd pygame bone$ python3 setup.py build #This will take a while, and may show many warnings bone$ sudo python3 setup.py install
from a python3 prompt, run >>>>>import pygame
If this executes without error, pygame is installed correctly.
Using pygame with beaglebone SPI display
In order to actually use pygame, the below Adafruit tutorial is useful. It automatically grabs the correct frame buffer and uses it to display your graphics on the small SPI LCD Displays:
Pointing Pygame to the Framebuffer
Note that a few things need to be changed from the above:
1. the print statements are incorrect for python3, and need to be removed or modified.
2. a cursor is present, which can be annoying when there is no mouse connected. To disable, add pygame.mouse.set_visible(False)
at around line 41 or so.
Embedded Linux Class by Mark A. Yoder