Instructions, plus build option for running full-screen applications (without X11) on vanilla 32-bit Raspbian installations. This doesn't commit the actual .so binaries, since there are at least two possible variants (as described in the README). |
||
---|---|---|
examples | ||
raylib | ||
raylib-c@6631fc4c6d | ||
.gitignore | ||
.gitmodules | ||
coords_demo.py | ||
LICENSE | ||
MANIFEST.in | ||
README.md | ||
setup.py | ||
test_dynamic.py | ||
test_pyray.py | ||
test_static.py | ||
windows_is_shit.bat |
Python Bindings for Raylib 3.5
New CFFI API static bindings. Faster, fewer bugs and easier to maintain than ctypes.
Advert
RetroWar: 8-bit Party Battle is out now. Defeat up to 15 of your friends in a tournament of 80s-inspired retro mini games.
Install
Option 1: Install from Pypi (easiest but currently out of date, Raylib 2.6 and Python 3.6 - 3.8)
Windows 10 (64 bit): Python 3.6 - 3.8
MacOS: Python 3.6 - 3.8
Linux (Ubuntu 16.04+): Python 3.6 - 3.8
We distribute a statically linked Raylib library, install from Pypi.
pip3 install raylib
Option 2: Install from github (Raylib 3.5, Python 3.6 - 3.9, Linux, awaiting builds for other platforms)
The version on Pypi may not always be up to date. If you want to test the latest version,
clone the git repo and make a symlink to the raylib
directory in your current project directory.
Option 3: Build from source (Raylib 3.5, all platforms)
If you're using a platform we dont have binary builds for yet then you can either use the dynamic binding with your own dll or else you will have to build from source. If you do build on a new platform please submit your binaries as a PR.
These instructions have been tested on Ubuntu 20.10 and 16.04. Mac should be very similar. Windows is probably different.
Clone this repo including submodules so you get correct version of Raylib.
git clone --recurse-submodules https://github.com/electronstudio/raylib-python-cffi
Build and install Raylib from the raylib-c directory.
cd raylib-python-cffi/raylib-c
mkdir build
cd build
cmake -DWITH_PIC=on -DSTATIC=on -DSHARED=on ..
sudo make install
Make a patched version of raylib header.
cd ../../raylib
cp raylib.h raylib_modified.h
patch -p0 <raylib_modified.h.patch
Build
cd static
pip3 install cffi
python3 build_linux.py
To build a complete set of libs for Python 3.6, 3.7, 3.8 and 3.9:
./build_linux_multi.sh
To update the Linux dynamic libs (names will be different on other platfroms):
cd ../..
rm raylib/dynamic/*.so*
cp -P /usr/local/lib/libraylib.so* raylib/dynamic/
Raspberry Pi
The integrated GPU hardware in a Raspberry Pi ("VideoCore") is rather idiosyncratic, resulting in a complex set of software options. Probably the most interesting two options for Raylib applications are:
-
Use the Broadcom proprietary Open GL ES 2.0 drivers, installed by Raspbian into
/opt/vc
. These are 32-bit only, and currently X11 doesn't use these for its acceleration, so this is most suitable for driving the entire HDMI output from one application with minimal overhead (no X11). -
Use the more recent open-source
vc4-fkms-v3d
kernel driver. This can run in either 32-bit or 64-bit, and X11 can use these, so using X11 is probably the more common choice here.
With option 2, the regular linux install instructions above should probably work as-is.
For option 1, then also follow the above instructions, but with these modifications:
- With
cmake
, usecmake -DWITH_PIC=on -DSTATIC=on -DSHARED=on -DPLATFORM='Raspberry Pi' ..
- Use
python3 build_rpi_nox.py
instead ofpython3 build_linux.py
- Use
build_rpi_nox_multi.sh
to build a complete set of libs if you need it (if you're not sure, then you almost certainly don't).
Use
raylib.static
Goal is make usage as similar to the original C as CFFI will allow. There are a few differences you can see in the examples. See test_static.py and examples/*.py for how to use.
from raylib.static import *
InitWindow(800, 450, b"Hello Raylib")
SetTargetFPS(60)
camera = ffi.new("struct Camera3D *", [[18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0])
SetCameraMode(camera[0], CAMERA_ORBITAL)
while not WindowShouldClose():
UpdateCamera(camera)
BeginDrawing()
ClearBackground(RAYWHITE)
BeginMode3D(camera[0])
DrawGrid(20, 1.0)
EndMode3D()
DrawText(b"Hellow World", 190, 200, 20, VIOLET)
EndDrawing()
CloseWindow()
raylib.pyray
Wrapper around the static bindings. Makes the names snakecase and converts strings to bytes automatically. See test_pyray.py.
from raylib.pyray import PyRay
from raylib.colors import *
pyray = PyRay()
pyray.init_window(800, 450, "Hello Pyray")
pyray.set_target_fps(60)
camera = pyray.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)
pyray.set_camera_mode(camera, pyray.CAMERA_ORBITAL)
while not pyray.window_should_close():
pyray.update_camera(camera)
pyray.begin_drawing()
pyray.clear_background(RAYWHITE)
pyray.begin_mode_3d(camera)
pyray.draw_grid(20, 1.0)
pyray.end_mode_3d()
pyray.draw_text("Hello world", 190, 200, 20, VIOLET)
pyray.end_drawing()
pyray.close_window()
raylib.dynamic
In addition to the API static bindings we have CFFI ABI dynamic bindings in order to avoid the need to compile a C extension module. There have been some weird failures with dynamic bindings and ctypes bindings before and often the failures are silent so you dont even know. Also the static bindings should be faster. Therefore I recommend the static ones...
BUT the dynamic bindings have the big advantage that you don't need to compile anything to install. You just need a Raylib DLL, which we supply for Windows/Mac/Linux.
See test_dynamic.py for how to use.
richlib
A simplified API for Raylib for use in education and to enable beginners to create 3d games
HELP WANTED
- converting more examples from C to python
- testing and building on more platforms
- sorting out binary wheel distribution for Mac/Win and compile-from-source distributtion for Linux