Skip to content

Working on Raspberry Pi

Ray edited this page Sep 7, 2023 · 21 revisions

To build your raylib game for Raspberry Pi you just need to download raylib git repository (or get the current release from here). All required libraries come with the raylib, no additional dependencies are required. raylib also comes with ready-to-use makefiles to compile source code and examples.

WARNING: PLATFORM_RPI is deprecated (only works with Raspbian Buster). Use PLATFORM_DRM for latest RPI OS Bullseye.

Supported Devices and OS

raylib supports the following Raspberry Pi models:

  • Raspberry Pi Zero (all models)
  • Raspberry Pi 1 (all models)
  • Raspberry Pi 2 (all models)
  • Raspberry Pi 3 (all models)
  • Raspberry Pi 4 (all models)

raylib supports the platforms/OSs, desktop and native modes:

Supported OpenGL backends

  • OpenGL ES 2.0 in native mode (no X11 required) (PLATFORM_DRM or PLATFORM_RPI)
  • OpenGL 1.1 on X11 desktop mode (PLATFORM_DESKTOP)
  • OpenGL 2.1 on X11 desktop mode (PLATFORM_DESKTOP)

By default, raylib should be compiled with PLATFORM_DESKTOP on classic X11-based Linux desktop environment, using the provided OpenGL desktop drivers. However, it is also possible to compile in native mode not depending on any windowing system (no X11 required).

When compiling for native mode, PLATFORM_DRM or PLATFORM_RPI should be used, depending on the RPI OS version, check previous point for details.

Compiling raylib source code

Before you can use raylib in your project you will have to compile it, but this is quick and easy!

Just navigate to raylib\src\ directory and run one of the following options depending on your needs:

1. To compile on desktop mode (X11 window)

make PLATFORM=PLATFORM_DESKTOP GRAPHICS=GRAPHICS_API_OPENGL_21

Raylib examples use GLSL 3.3 shaders. Older Raspberry Pi's 0-3 only support upto GLSL 1.2. If you are on Raspberry Pi OS desktop on something lower than RPi4 you will see that shaders will default to a base shader and examples may not look as intended. To fix this, we need to tell Raylib to load GLSL 1.2 versions of the shader in the .c file of the example which will look something like this:

#if defined(PLATFORM_DESKTOP)
    #define GLSL_VERSION            120 // Change this back to 330 if compiling for a platform that supports GLSL3.3
#else   // PLATFORM_ANDROID, PLATFORM_WEB
    #define GLSL_VERSION            100
#endif

Also, ensure the correct versions of the shaders are available in the raylib/examples/resources/shaders/glsl120 folder. Troubleshooting is easier while running your example from a terminal as raylib will log the errors over there.

NOTE on compilation errors: To use raylib on the Raspberry Pi desktop, you need to had previously installed all desktop window-dev system libraries, if you just downloaded Raspberry Pi OS Desktop, maybe it comes with required libraries installed but if it complains on compilation, just make sure to install the following libraries:

sudo apt-get install --no-install-recommends raspberrypi-ui-mods lxterminal gvfs
sudo apt-get install libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev libxi-dev libasound2-dev mesa-common-dev libgl1-mesa-dev

2. To compile in native mode (no X11)

On Rapsberry Pi 0-4 using RPI OS Bullseye or newer:

make PLATFORM=PLATFORM_DRM

NOTE: To compile raylib in native mode on Raspberry Pi 4, you need the specific DRM libraries:

sudo apt-get install libdrm-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev

raylib also works on DietPi distribution, following libraries are required:

sudo apt-get install libraspberrypi-dev raspberrypi-kernel-headers
sudo apt-get install build-essential

Compiling raylib examples

Just move to folder raylib/examples/ and run the same make command you used to compile raylib

Clone this wiki locally