### Quickstart Raylib Python Example Source: https://electronstudio.github.io/raylib-python-cffi/_sources/README A basic "Hello, World!" example demonstrating how to initialize a window, clear the background, draw text, and close the window using the pyray module. ```Python from pyray import * init_window(800, 450, "Hello") while not window_should_close(): begin_drawing() clear_background(WHITE) draw_text("Hello world", 190, 200, 20, VIOLET) end_drawing() close_window() ``` -------------------------------- ### Raylib Python Quickstart Source: https://electronstudio.github.io/raylib-python-cffi/README A basic example demonstrating how to initialize a Raylib window, clear the background, draw text, and close the window using the raylib Python bindings. ```python from pyray import * init_window(800, 450, "Hello") while not window_should_close(): begin_drawing() clear_background(WHITE) draw_text("Hello world", 190, 200, 20, VIOLET) end_drawing() close_window() ``` -------------------------------- ### Raylib Python CFFI Basic Window Initialization and 3D Drawing Source: https://electronstudio.github.io/raylib-python-cffi/_sources/raylib Demonstrates basic window initialization, setting target FPS, camera setup for orbital control, and drawing a 3D grid and text within the raylib-python-cffi framework. This example utilizes the C API for direct interaction with raylib functions. ```Python from raylib 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]) while not WindowShouldClose(): UpdateCamera(camera, CAMERA_ORBITAL) BeginDrawing() ClearBackground(RAYWHITE) BeginMode3D(camera[0]) DrawGrid(20, 1.0) EndMode3D() DrawText(b"Hellow World", 190, 200, 20, VIOLET) EndDrawing() CloseWindow() ``` -------------------------------- ### Windows Manual Build: Create Wheel Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Builds a Python wheel distribution for raylib-python-cffi on Windows. This involves cleaning previous builds, installing necessary tools (cffi, wheel), and running the setup script. ```powershell rmdir /Q /S build pip3 install cffi pip3 install wheel python setup.py bdist_wheel ``` -------------------------------- ### Install Setuptools Source: https://electronstudio.github.io/raylib-python-cffi/_sources/README Command to install the setuptools package, often required for Python package installation. ```Shell python3 -m pip install setuptools ``` -------------------------------- ### Build and Install Binary Wheel Distribution Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Creates a binary wheel distribution of the raylib-python-cffi package, which is a standard format for distributing Python packages. It first installs the `wheel` package and then runs the `setup.py` script to build the wheel. Finally, it installs the generated wheel file. ```bash pip3 install wheel python3 setup.py bdist_wheel pip3 install dist/raylib*.whl ``` -------------------------------- ### Install Raylib Python (Binary Wheel) Source: https://electronstudio.github.io/raylib-python-cffi/RPI Installs the Raylib Python bindings using a pre-compiled binary wheel. This is the simplest method and requires no compilation. It uses pip for installation and supports `--break-system-packages` for environments where system-wide package management is restricted. ```Python python -m pip install --break-system-packages raylib ``` -------------------------------- ### Macos: Build and Install Python Module Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Builds and installs the raylib-python-cffi Python module on macOS. This includes installing `cffi`, cleaning previous build artifacts, running the Python build script, installing the `wheel` package, and finally installing the module using `setup.py`. ```bash pip3 install cffi rm -rf build raylib/_raylib_cffi.* python3 raylib/build.py pip3 install wheel python3 setup.py install ``` -------------------------------- ### Build and Install Raylib Python Wheel (Windows) Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Commands to prepare the build environment, build a binary wheel distribution for Raylib Python, and then install it. ```Batch rmdir /Q /S build pip3 install cffi pip3 install wheel python setup.py bdist_wheel pip3 install dist\raylib-3.7.0-cp37-cp37m-win_amd64.whl ``` -------------------------------- ### Build and Install Raylib-Python-Cffi Module Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Installs the necessary cffi package, cleans previous build artifacts, builds the Raylib CFFI module using a Python script, packages it as a wheel, and installs it. ```python pip3 install cffi rm -rf build raylib/_raylib_cffi.* python3 raylib/build.py pip3 install wheel python3 setup.py install ``` -------------------------------- ### Linux: Install Dependencies and Build Raylib C Library (Static) Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Installs necessary development packages on Debian-based systems (like Ubuntu) and then builds and installs the Raylib C library statically. It configures the build with specific features like JPG and FLAC support and position-independent code. ```bash sudo apt install cmake libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev pkg-config cmake cd raylib-python-cffi/raylib-c mkdir build cd build cmake -DCUSTOMIZE_BUILD=ON -DSUPPORT_FILEFORMAT_JPG=ON -DSUPPORT_FILEFORMAT_FLAC=ON -DWITH_PIC=ON -DCMAKE_BUILD_TYPE=Release .. sudo make install export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ``` -------------------------------- ### Install Built Wheel (Linux) Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Installs the generated wheel distribution of raylib-python-cffi on Linux. The wildcard `*` is used as the exact filename may differ. ```bash pip3 install dist/raylib*.whl ``` -------------------------------- ### Install Raylib SDL Backend Source: https://electronstudio.github.io/raylib-python-cffi/_sources/README Commands to uninstall the static raylib package and install the SDL backend version, which offers better controller support. ```Shell python3 -m pip uninstall raylib python3 -m pip install raylib_sdl ``` -------------------------------- ### Install Raylib Dynamic Backend Source: https://electronstudio.github.io/raylib-python-cffi/_sources/README Commands to uninstall the static raylib package and install the dynamic backend version. ```Shell python3 -m pip uninstall raylib python3 -m pip install raylib_dynamic ``` -------------------------------- ### Macos: Build and Install Raylib C Library Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Builds and installs the Raylib C library on macOS. This involves navigating to the `raylib-c` directory, creating a build directory, configuring the build with CMake (enabling position-independent code), compiling, and installing. ```bash cd raylib-python-cffi/raylib-c/ mkdir build cd build cmake -DWITH_PIC=on -DCMAKE_BUILD_TYPE=Release .. make sudo make install cd ../.. ``` -------------------------------- ### Install Built Wheel (Windows) Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Installs the previously built wheel distribution of raylib-python-cffi on Windows. The filename may vary based on the Python version and system architecture. ```powershell pip3 install dist\raylib-3.7.0-cp37-cp37m-win_amd64.whl ``` -------------------------------- ### Install Raylib with Homebrew (macOS) Source: https://electronstudio.github.io/raylib-python-cffi/_sources/README Commands to install pkg-config and raylib using Homebrew on macOS, prerequisites for building from source. ```Shell brew install pkg-config brew install raylib ``` -------------------------------- ### Initialize and Draw with Pyray Source: https://electronstudio.github.io/raylib-python-cffi/_sources/pyray Demonstrates basic window initialization, camera setup, and drawing operations using the pyray library. It includes clearing the background, drawing a 3D grid, and displaying text. ```Python import pyray as pr pr.init_window(800, 450, "Hello Pyray") pr.set_target_fps(60) camera = pr.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0) while not pr.window_should_close(): pr.update_camera(camera, pr.CAMERA_ORBITAL) pr.begin_drawing() pr.clear_background(pr.RAYWHITE) pr.begin_mode_3d(camera) pr.draw_grid(20, 1.0) pr.end_mode_3d() pr.draw_text("Hello world", 190, 200, 20, pr.VIOLET) pr.end_drawing() pr.close_window() ``` -------------------------------- ### Install Raylib Python from Source using Pip Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Command to install the Raylib Python package from source using pip, ensuring it builds from source and forces a reinstall. ```Shell pip3 install --no-cache-dir --no-binary raylib --upgrade --force-reinstall raylib ``` -------------------------------- ### Linux Manual Build: Install Dependencies Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Installs essential development packages on Debian-based Linux systems required for compiling Raylib and its Python bindings. This includes CMake, ALSA, OpenGL, X11, and pkg-config. ```bash sudo apt install cmake libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev pkg-config cmake ``` -------------------------------- ### Install Raylib-Python-CFFI (Binary Wheel) Source: https://electronstudio.github.io/raylib-python-cffi/_sources/RPI Installs the raylib-python-cffi library using a pre-compiled binary wheel for Raspberry Pi OS Bullseye (64-bit, X11 mode). An alternative DRM wheel is available for framebuffer usage without X11, but only one can be installed. ```bash python -m pip install --break-system-packages raylib ``` -------------------------------- ### Install Raylib Python Package Source: https://electronstudio.github.io/raylib-python-cffi/_sources/README Command to install the raylib Python package version 5.5.0.2 using pip. ```Shell pip3 install raylib==5.5.0.2 --break-system-packages ``` -------------------------------- ### Raylib Dynamic Bindings Example Source: https://electronstudio.github.io/raylib-python-cffi/dynamic An example script showcasing the usage of dynamic Raylib bindings in Python. This script is intended to be run with the 'rl.' prefix convention. ```python # Example usage of dynamic bindings (refer to test_dynamic.py for full example) from raylib import rl rl.init_window(800, 600, "Raylib Dynamic Bindings Test") rl.close_window() ``` -------------------------------- ### Compile Raylib from Source (X11 Mode) Source: https://electronstudio.github.io/raylib-python-cffi/_sources/RPI Compiles the raylib library from source for X11 mode on Raspberry Pi. This involves updating packages, installing dependencies (cmake, mesa, drm, glfw), cloning the raylib repository, configuring the build with specific CMake options, compiling, and installing. It also includes steps to copy GLFW headers and then install the raylib-python-cffi wheel. ```bash sudo apt update sudo apt install python3-pip cmake libegl1-mesa-dev libgbm-dev libgles2-mesa-dev libdrm-dev libglfw3-dev git clone https://github.com/raysan5/raylib.git --branch 5.0 --single-branch cd raylib mkdir build rm -rf build/* cd build cmake -DPLATFORM="Desktop" -DOPENGL_VERSION=2.1 -DBUILD_EXAMPLES=OFF -DCUSTOMIZE_BUILD=ON -DSUPPORT_FILEFORMAT_JPG=ON -DSUPPORT_FILEFORMAT_FLAC=ON -DWITH_PIC=ON -DCMAKE_BUILD_TYPE=Release .. make sudo make install sudo cp -r ../src/external/glfw/include/GLFW /usr/local/include/ ``` ```bash python3 -m pip install --break-system-packages setuptools python3 -m pip install --no-cache-dir --no-binary raylib --upgrade --force-reinstall --break-system-packages raylib==5.5.0.0 ``` -------------------------------- ### Build Raylib with CMake (Linux/Mac) Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING This snippet shows how to download, compile, and install Raylib using CMake on Linux or macOS systems. It includes setting build options and exporting the PKG_CONFIG_PATH. ```bash wget https://github.com/raysan5/raylib/archive/refs/tags/5.5.zip unzip 5.5.zip cd raylib-5.5 mkdir build cd build cmake -DCUSTOMIZE_BUILD=ON -DSUPPORT_FILEFORMAT_JPG=ON -DSUPPORT_FILEFORMAT_FLAC=ON -DWITH_PIC=ON -DCMAKE_BUILD_TYPE=Release .. make sudo make install export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ``` -------------------------------- ### Install raylib-python-cffi from Source (Pip) Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING This command installs the raylib-python-cffi library using Pip, forcing a build from source. This is useful when pre-compiled binaries are not compatible or when a specific Raylib version is needed. ```bash pip3 install --no-cache-dir --no-binary raylib --upgrade --force-reinstall raylib ``` -------------------------------- ### Web Browser Project Setup for Raylib Python Source: https://electronstudio.github.io/raylib-python-cffi/README Configuration for running a Raylib Python project in a web browser using Pygbag, specifying dependencies. ```python # /// script # dependencies = [ # "cffi", # "raylib" # ] ``` -------------------------------- ### Install Raylib DRM Backend Source: https://electronstudio.github.io/raylib-python-cffi/_sources/README Commands to uninstall the static raylib package and install the DRM backend version, suitable for Linux devices without X11/Wayland. ```Shell python3 -m pip uninstall raylib python3 -m pip install raylib_drm ``` -------------------------------- ### Raylib Python Installation Script Source: https://electronstudio.github.io/raylib-python-cffi/README A Python script snippet showing the command to install the raylib Python package using pip, including a specific version. ```python pip3 install raylib==5.5.0.2 --break-system-packages ``` -------------------------------- ### Build Raylib using CMake (Linux/Mac) Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING This snippet shows the commands to download, compile, and install Raylib using CMake on Linux or macOS. It includes setting build options and exporting the PKG_CONFIG_PATH. ```Shell wget https://github.com/raysan5/raylib/archive/refs/tags/5.5.zip unzip 5.5.zip cd raylib-5.5 mkdir build cd build cmake -DCUSTOMIZE_BUILD=ON -DSUPPORT_FILEFORMAT_JPG=ON -DSUPPORT_FILEFORMAT_FLAC=ON -DWITH_PIC=ON -DCMAKE_BUILD_TYPE=Release .. make sudo make install export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ``` -------------------------------- ### Install Raylib Dynamic Bindings Source: https://electronstudio.github.io/raylib-python-cffi/dynamic Installs the dynamic bindings for Raylib Python using pip. This method avoids the need to compile C extension modules, requiring only a Raylib DLL. ```shell python3 -m pip install raylib_dynamic ``` -------------------------------- ### Compile Raylib from Source (DRM Mode) Source: https://electronstudio.github.io/raylib-python-cffi/RPI Compiles Raylib from source code in DRM mode for use without X11 on Raspberry Pi. This process includes removing previous Raylib and GLFW installations, updating package lists, installing build dependencies (cmake, mesa, drm), cloning the Raylib repository, configuring the build with CMake for shared libraries and DRM platform, compiling, and installing. It concludes by reinstalling the raylib Python package. ```Shell sudo apt remove raylib raylib-dev libraylib libraylib-dev sudo rm /usr/local/lib/pkgconfig/raylib.pc sudo rm -rf /usr/local/lib/libraylib.* /usr/lib/libraylib.* sudo apt remove libglfw3-dev libglfw3 sudo rm -rf /usr/local/include/GLFW ``` ```Shell sudo apt update sudo apt install python3-pip cmake libegl1-mesa-dev libgbm-dev libgles2-mesa-dev libdrm-dev git clone https://github.com/raysan5/raylib.git --branch 5.0 --single-branch cd raylib mkdir build rm rf build/* cd build cmake -DPLATFORM="DRM" -DBUILD_EXAMPLES=OFF -DCUSTOMIZE_BUILD=ON -DSUPPORT_FILEFORMAT_JPG=ON -DSUPPORT_FILEFORMAT_FLAC=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr .. make sudo make install ``` ```Shell python3 -m pip install --break-system-packages setuptools python3 -m pip install --no-cache-dir --no-binary raylib --upgrade --force-reinstall --break-system-packages raylib==5.5.0.0 ``` -------------------------------- ### Linux Manual Build: Compile Raylib Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Compiles and installs the Raylib C library on Linux using CMake. This command includes custom build options and sets the PKG_CONFIG_PATH for system-wide access. ```bash cd raylib-python-cffi/raylib-c mkdir build cd build cmake -DCUSTOMIZE_BUILD=ON -DSUPPORT_FILEFORMAT_JPG=ON -DSUPPORT_FILEFORMAT_FLAC=ON -DWITH_PIC=ON -DCMAKE_BUILD_TYPE=Release .. sudo make install export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ``` -------------------------------- ### Linux Manual Build: Build Python Library Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Builds the Python CFFI bindings for raylib on Linux. This involves installing cffi, cleaning previous build artifacts, and executing the build script. ```bash pip3 install cffi rm -rf build raylib/_raylib_cffi.* python3 raylib/build.py ``` -------------------------------- ### Build Python Library Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Builds the Python bindings for raylib using cffi. This involves installing the cffi package, cleaning previous build artifacts, and running the build script. ```bash pip3 install cffi rm -rf build raylib/_raylib_cffi.* python3 raylib/build.py ``` -------------------------------- ### Build and Install Raylib C Library (macOS) Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Builds and installs the Raylib C library from the raylib-c directory using CMake and Make. It configures the build with Position Independent Code (PIC) and Release build type. ```bash cd raylib-python-cffi/raylib-c/ mkdir build cd build cmake -DWITH_PIC=on -DCMAKE_BUILD_TYPE=Release .. make sudo make install cd ../.. ``` -------------------------------- ### Prepare for Raylib Compilation (DRM Mode) Source: https://electronstudio.github.io/raylib-python-cffi/_sources/RPI Removes existing raylib and GLFW installations to prepare for a clean build of raylib in DRM mode. This includes removing package files, configuration files, and library binaries for both raylib and GLFW. ```bash sudo apt remove raylib raylib-dev libraylib libraylib-dev sudo rm /usr/local/lib/pkgconfig/raylib.pc sudo rm -rf /usr/local/lib/libraylib.* /usr/lib/libraylib.* sudo apt remove libglfw3-dev libglfw3 sudo rm -rf /usr/local/include/GLFW ``` -------------------------------- ### Compile Raylib from Source (X11 Mode) Source: https://electronstudio.github.io/raylib-python-cffi/RPI Compiles Raylib from source code in X11 mode for use with Raylib Python. This involves updating package lists, installing build dependencies (cmake, mesa, drm, glfw), cloning the Raylib repository, configuring the build with CMake, compiling, and installing. Finally, it reinstalls the raylib Python package, forcing a recompile. ```Shell sudo apt update sudo apt install python3-pip cmake libegl1-mesa-dev libgbm-dev libgles2-mesa-dev libdrm-dev libglfw3-dev git clone https://github.com/raysan5/raylib.git --branch 5.0 --single-branch cd raylib mkdir build rm -rf build/* cd build cmake -DPLATFORM="Desktop" -DOPENGL_VERSION=2.1 -DBUILD_EXAMPLES=OFF -DCUSTOMIZE_BUILD=ON -DSUPPORT_FILEFORMAT_JPG=ON -DSUPPORT_FILEFORMAT_FLAC=ON -DWITH_PIC=ON -DCMAKE_BUILD_TYPE=Release .. make sudo make install sudo cp -r ../src/external/glfw/include/GLFW /usr/local/include/ ``` ```Shell python3 -m pip install --break-system-packages setuptools python3 -m pip install --no-cache-dir --no-binary raylib --upgrade --force-reinstall --break-system-packages raylib==5.5.0.0 ``` -------------------------------- ### Importing Raylib Dynamic Bindings Source: https://electronstudio.github.io/raylib-python-cffi/_sources/dynamic Demonstrates how to import and use functions from the Raylib dynamic bindings. This method ensures compatibility with both static and dynamic binding installations by using the 'rl.' prefix for function calls. ```Python from raylib import rl # Access functions using the 'rl.' prefix # For example: # rl.init_window(800, 600, "Raylib Dynamic Bindings") ``` -------------------------------- ### Linux: Build Raylib C Library (Shared) Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Builds the Raylib C library as shared libraries on Linux. This is an optional step if you intend to use the `raylib_dynamic` Python binding. It cleans the build directory, configures CMake for shared libraries and position-independent code, builds, and installs. ```bash rm -rf * cmake -DWITH_PIC=on -DBUILD_SHARED_LIBS=on -DCMAKE_BUILD_TYPE=Release .. make sudo make install ``` -------------------------------- ### Import All Pyray Functions Source: https://electronstudio.github.io/raylib-python-cffi/_sources/pyray Shows an alternative way to import functions from the pyray library, allowing direct use of function names without the 'pr.' prefix. This is useful for simplifying code, especially in examples. ```Python from pyray import * init_window(800, 450, "Raylib texture test") ... ``` -------------------------------- ### Linux Manual Build: Create Wheel Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Creates a binary wheel distribution for the raylib-python-cffi library on Linux after the Python library has been built. ```bash pip3 install wheel python3 setup.py bdist_wheel ``` -------------------------------- ### Basic Raylib Window and Drawing in Python Source: https://electronstudio.github.io/raylib-python-cffi/README Demonstrates how to initialize a Raylib window, handle the main loop, clear the background, draw text, and close the window using the pyray library. It also includes platform-specific window resizing and asynchronous loop handling. ```Python import asyncio import platform from pyray import * async def main(): # You MUST have an async main function init_window(500, 500, "Hello") platform.window.window_resize() # You MAY want to add this line while not window_should_close(): begin_drawing() clear_background(WHITE) draw_text("Hello world", 190, 200, 20, VIOLET) end_drawing() await asyncio.sleep(0) # You MUST call this in your main loop close_window() asyncio.run(main()) ``` -------------------------------- ### Compile Raylib from Source (DRM Mode) Source: https://electronstudio.github.io/raylib-python-cffi/_sources/RPI Compiles the raylib library from source for DRM mode on Raspberry Pi 4, suitable for framebuffer usage without X11. It involves updating packages, installing dependencies (cmake, mesa, drm), cloning the raylib repository, configuring the build with specific CMake options for DRM and shared libraries, compiling, and installing to /usr. Finally, it installs the raylib-python-cffi wheel. ```bash sudo apt update sudo apt install python3-pip cmake libegl1-mesa-dev libgbm-dev libgles2-mesa-dev libdrm-dev git clone https://github.com/raysan5/raylib.git --branch 5.0 --single-branch cd raylib mkdir build rm rf build/* cd build cmake -DPLATFORM="DRM" -DBUILD_EXAMPLES=OFF -DCUSTOMIZE_BUILD=ON -DSUPPORT_FILEFORMAT_JPG=ON -DSUPPORT_FILEFORMAT_FLAC=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr .. make sudo make install ``` ```bash python3 -m pip install --break-system-packages setuptools python3 -m pip install --no-cache-dir --no-binary raylib --upgrade --force-reinstall --break-system-packages raylib==5.5.0.0 ``` -------------------------------- ### Windows Manual Build: Compile Raylib Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Compiles the Raylib C library on Windows using CMake and MSBuild. It specifies build configurations and copies the resulting static library to the parent directory. ```powershell cd raylib-python-cffi/raylib-c mkdir build cd build cmake -DWITH_PIC=on -DCMAKE_BUILD_TYPE=Release .. msbuild raylib.sln /target:raylib /property:Configuration=Release copy raylib\Release\raylib.lib ..\.. ``` -------------------------------- ### Build Raylib using CMake and MSBuild (Windows) Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Builds the Raylib C library on Windows using CMake and MSBuild, specifying build configurations and outputting the static library. ```Batch cd raylib-python-cffi/raylib-c mkdir build cd build cmake -DWITH_PIC=on -DCMAKE_BUILD_TYPE=Release .. msbuild raylib.sln /target:raylib /property:Configuration=Release copy raylib\Release\raylib.lib ..\.. ``` -------------------------------- ### Clone raylib-python-cffi Repository Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Clones the raylib-python-cffi GitHub repository, including all submodules, which is necessary for obtaining the correct version of Raylib for building. ```bash git clone --recurse-submodules https://github.com/electronstudio/raylib-python-cffi ``` -------------------------------- ### Clone Repository Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Clones the raylib-python-cffi repository, ensuring that submodules are included to obtain the correct version of Raylib. ```bash git clone --recurse-submodules https://github.com/electronstudio/raylib-python-cffi ``` -------------------------------- ### Clone Raylib-Python-Cffi Repository Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Clones the Raylib-Python-Cffi GitHub repository, including all submodules, to ensure the correct version of Raylib is obtained. ```bash git clone --recurse-submodules https://github.com/electronstudio/raylib-python-cffi ``` -------------------------------- ### Clone Raylib Python Repository (Windows) Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Clones the raylib-python-cffi repository, including submodules, which is necessary for the Windows manual build process. ```Shell git clone --recurse-submodules https://github.com/electronstudio/raylib-python-cffi ``` -------------------------------- ### Conditional Audio Initialization Source: https://electronstudio.github.io/raylib-python-cffi/README Shows how to conditionally initialize the audio device, checking if the current platform is not Emscripten, as audio might not work on the current Emscripten version. ```Python if platform.system() != "Emscripten": # audio may not work on current version of emscripten init_audio_device() ``` -------------------------------- ### Run Raylib Python CFFI in Browser with Pygbag Source: https://electronstudio.github.io/raylib-python-cffi/_sources/README This Python script demonstrates how to initialize a Raylib window, draw text, and handle the main loop, designed to be run in a web browser using Pygbag. It requires the 'cffi' and 'raylib' libraries and uses asyncio for the main loop. ```Python # /// script # dependencies = [ # "cffi", # "raylib" # ] # /// import asyncio import platform from pyray import * async def main(): # You MUST have an async main function init_window(500, 500, "Hello") platform.window.window_resize() # You MAY want to add this line while not window_should_close(): begin_drawing() clear_background(WHITE) draw_text("Hello world", 190, 200, 20, VIOLET) end_drawing() await asyncio.sleep(0) # You MUST call this in your main loop close_window() asyncio.run(main()) ``` -------------------------------- ### Create Python Virtual Environment Source: https://electronstudio.github.io/raylib-python-cffi/_sources/README Commands to create and activate a Python virtual environment for managing project dependencies. ```Shell python3 -m venv venv source venv/bin/activate ``` -------------------------------- ### Conditional Audio Initialization for Web Browsers Source: https://electronstudio.github.io/raylib-python-cffi/_sources/README This Python code snippet shows how to conditionally initialize the audio device, preventing errors when running in environments like Emscripten (web browsers) where audio might not be supported or function correctly. ```Python if platform.system() != "Emscripten": # audio may not work on current version of emscripten init_audio_device() ``` -------------------------------- ### Update Linux Dynamic Libraries Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Copies the compiled Raylib shared libraries (`.so` files) to the `dynamic/raylib/` directory within the project, enabling the use of `raylib_dynamic` bindings. ```bash rm dynamic/raylib/*.so* cp -P /usr/local/lib/libraylib.so* dynamic/raylib/ ``` -------------------------------- ### Fix Symlink on Windows Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Copies the raylib.h header file to the correct location within the cloned repository structure to resolve a symlink issue on Windows. ```Batch cd raylib-python-cffi copy raylib-c\src\raylib.h raylib\raylib.h ``` -------------------------------- ### Windows Manual Build: Fix Symlink Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING On Windows, this command copies the raylib.h header file to the correct location within the cloned repository to resolve a symlink issue. ```powershell cd raylib-python-cffi copy raylib-c\src\raylib.h raylib\raylib.h ``` -------------------------------- ### Build Multi-Version Python Libraries (Linux) Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Executes a script to build the Python bindings for multiple Python versions (3.6-3.9) on Linux. It specifically uses `build_multi_linux.sh` to ensure compatibility with Linux package requirements, such as `manylinux2014_x86_64`. ```bash ./raylib/build_multi.sh ``` -------------------------------- ### Update Linux Dynamic Libraries Source: https://electronstudio.github.io/raylib-python-cffi/BUILDING Copies the Raylib shared libraries (`.so` files) to the `dynamic/raylib/` directory. This step is specific to Linux and ensures the dynamic binding can locate the libraries. ```bash rm dynamic/raylib/*.so* cp -P /usr/local/lib/libraylib.so* dynamic/raylib/ ``` -------------------------------- ### Package Raylib Python CFFI App with Nuitka Source: https://electronstudio.github.io/raylib-python-cffi/_sources/README This command demonstrates how to use the Nuitka compiler to create a standalone executable for a Raylib Python CFFI application. It specifies a one-file output and an icon for Linux. ```Shell pip3 install nuitka cd examples/textures python3 -m nuitka --onefile --linux-onefile-icon resources/wabbit_alpha.png textures_bunnymark.py ``` -------------------------------- ### Raylib Python CFFI Portable Function Usage Source: https://electronstudio.github.io/raylib-python-cffi/_sources/raylib Illustrates a more portable way to use raylib functions in Python by prefixing them with 'rl.' This approach allows the same code to work with dynamic bindings, enhancing flexibility. It requires importing 'ffi' and 'rl' from the raylib library. ```Python from raylib import ffi, rl, colors rl.InitWindow(800, 450, b"Hello Raylib") rl.SetTargetFPS(60) ... ``` -------------------------------- ### Linux Manual Build: Compile Raylib Shared Libraries Source: https://electronstudio.github.io/raylib-python-cffi/_sources/BUILDING Optionally compiles Raylib as shared libraries on Linux, which is necessary for using the `raylib_dynamic` binding. This involves reconfiguring CMake with `BUILD_SHARED_LIBS=on`. ```bash rm -rf * cmake -DWITH_PIC=on -DBUILD_SHARED_LIBS=on -DCMAKE_BUILD_TYPE=Release .. make sudo make install ``` -------------------------------- ### Using Pyray for Raylib Access Source: https://electronstudio.github.io/raylib-python-cffi/_sources/dynamic An alternative method for accessing Raylib functions using the 'pyray' import. While this approach offers a seamless experience without the 'rl.' prefix, it has undergone less testing compared to the 'rl.' prefix method. ```Python import pyray # Access functions directly via pyray # For example: # pyray.init_window(800, 600, "Raylib Pyray Access") ``` -------------------------------- ### Importing Raylib Functions (Dynamic Bindings) Source: https://electronstudio.github.io/raylib-python-cffi/dynamic Demonstrates how to import Raylib functions when using dynamic bindings. Unlike static bindings, you must import the 'rl' module and access functions with the 'rl.' prefix. This approach ensures compatibility with both static and dynamic bindings. ```python from raylib import rl # Access functions using rl. prefix rl.init_window(800, 600, "Raylib Dynamic Bindings") ```