### Build ALL Raylib Examples with MinGW Make Source: https://github.com/raysan5/raylib/wiki/Working-on-Windows Use this command in the `raylib/examples/` directory to build all examples with the MinGW make tool. Ensure MinGW is installed and configured. ```bash mingw32-make PLATFORM=PLATFORM_DESKTOP ``` -------------------------------- ### Install Client Dependencies and Run Dev Server Source: https://github.com/raysan5/raylib/wiki/Creating-Discord-Activities-with-raylib Navigate to the client directory, install necessary npm packages, and start the development server to preview your application. ```sh cd client npm install npm run dev ``` -------------------------------- ### Environment Variables Setup Source: https://github.com/raysan5/raylib/wiki/Working-for-Android-(on-macOS) Adds necessary Android SDK and NDK directories to the system's PATH for command-line access. Ensure paths are correct for your installation. ```bash export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk export PATH=$PATH:$ANDROID_SDK_ROOT/emulator export PATH=$PATH:$ANDROID_SDK_ROOT/build-tools/36.0.0-rc1 export PATH=$PATH:$ANDROID_SDK_ROOT/tools export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools export ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/28.0.12674087 export PATH=$PATH:$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin ``` -------------------------------- ### Install build tools Source: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux Install essential compilation tools and git for cloning the repository. ```bash sudo apt install build-essential git ``` -------------------------------- ### Build examples with GNU make Source: https://github.com/raysan5/raylib/blob/master/examples/README.md Commands to build all, module-specific, or individual examples using the make utility. ```bash make ``` ```bash make [module] ``` ```bash make [module]/[name] ``` -------------------------------- ### Install raylib via vcpkg Source: https://github.com/raysan5/raylib/wiki/Working-on-Windows Commands to clone vcpkg, bootstrap it, and install raylib for Windows. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg bootstrap-vcpkg.bat vcpkg integrate install vcpkg install raylib ``` ```bash vcpkg install raylib:x64-windows ``` -------------------------------- ### Copy Example Resources Source: https://github.com/raysan5/raylib/blob/master/examples/CMakeLists.txt Copies all specified example resource files to a 'resources/' directory in the build output. ```cmake file(COPY ${example_resources} DESTINATION "resources/") ``` -------------------------------- ### Build raylib examples with Make Source: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux Compile raylib examples using Make. Specify PLATFORM and RAYLIB_LIBTYPE for different build configurations. ```bash make PLATFORM=PLATFORM_DESKTOP ``` ```bash make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED ``` -------------------------------- ### Build examples with Zig Source: https://github.com/raysan5/raylib/blob/master/examples/README.md Commands to compile or run examples using the Zig toolchain, which supports cross-compilation. ```bash zig build ``` ```bash zig build [module] ``` ```bash zig build [example] ``` -------------------------------- ### List installed raylib files Source: https://github.com/raysan5/raylib/wiki/Working-on-FreeBSD Verify the installation and locate library and header files. ```text $ pkg info -l raylib raylib-5.5: /usr/local/include/raylib.h /usr/local/include/raymath.h /usr/local/include/rlgl.h /usr/local/lib/cmake/raylib/raylib-config-version.cmake /usr/local/lib/cmake/raylib/raylib-config.cmake /usr/local/lib/libraylib.so /usr/local/lib/libraylib.so.5.5.0 /usr/local/lib/libraylib.so.550 /usr/local/libdata/pkgconfig/raylib.pc /usr/local/share/licenses/raylib-5.5/LICENSE /usr/local/share/licenses/raylib-5.5/ZLIB /usr/local/share/licenses/raylib-5.5/catalog.mk ``` -------------------------------- ### Install build-essential tools Source: https://github.com/raysan5/raylib/wiki/Working-on-Chrome-OS Installs GCC, make, and other essential tools required for compiling C/C++ projects. ```bash sudo apt install build-essential ``` -------------------------------- ### Include Install Configurations Source: https://github.com/raysan5/raylib/blob/master/src/CMakeLists.txt Includes the InstallConfigurations module, which defines how the library will be installed when 'cmake --install' is executed. ```cmake include(InstallConfigurations) ``` -------------------------------- ### Install Emscripten SDK Tools Source: https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5) Commands to install and activate the latest Emscripten tools. Ensure Python and Git are installed and accessible. ```bash emsdk update emsdk install latest emsdk activate latest ``` -------------------------------- ### Download and install GLFW3 Source: https://github.com/raysan5/raylib/wiki/Working-on-Chrome-OS Downloads, unzips, and installs GLFW3 from source, enabling shared library builds. ```bash wget https://github.com/glfw/glfw/releases/download/3.2.1/glfw-3.2.1.zip unzip glfw-3.2.1.zip cd glfw-3.2.1 cmake -DBUILD_SHARED_LIBS=ON sudo make install ``` -------------------------------- ### Install dependencies by distribution Source: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux Commands to install required development libraries for audio, graphics, and windowing systems. ```bash sudo apt install libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev ``` ```bash sudo dnf install alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel libatomic ``` ```bash rpm-ostree install alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel libatomic ``` ```bash sudo dnf install libX11-devel libXrandr-devel libXi-devel libXcursor-devel mesa-libGL-devel pulseaudio-libs-devel libdrm-devel libXinerama-devel ``` ```bash sudo pacman -S alsa-lib mesa libx11 libxrandr libxi libxcursor libxinerama ``` ```bash sudo nano /etc/pacman.d/mirrorlist Server = htpps://steamdeck-packages.steamos.cloud/archlinux-mirror/$repo/os/$arch sudo pacman -S base-devel glibc linux-api-header alsa-lib mesa xorgproto libx11 libxrandr libxi libxcursor libxinerama libxext libxrender libxfixes ``` ```bash sudo xbps-install make alsa-lib-devel libglvnd-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel mesa MesaLib-devel ``` ```bash sudo xbps-install mesa-dri mesa-intel-dri ``` -------------------------------- ### Install raylib on FreeBSD Source: https://github.com/raysan5/raylib/wiki/Working-on-FreeBSD Use the package manager to install prebuilt binaries or the ports collection to build from source. ```console # pkg install raylib ``` ```console # cd /usr/ports/devel/raylib && make install clean ``` -------------------------------- ### Install Homebrew Source: https://github.com/raysan5/raylib/wiki/Compile-for-OSX Execute this command in Terminal to install the Homebrew package manager. ```bash /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ``` -------------------------------- ### Install raylib via Homebrew Source: https://github.com/raysan5/raylib/wiki/Compile-for-OSX Use Homebrew to install the raylib library package. ```bash brew install raylib ``` -------------------------------- ### Compile Specific Example (Core Basic Window) Source: https://github.com/raysan5/raylib/blob/master/projects/Notepad++/npes_saved_w64devkit.txt Compiles a specific example, 'core/core_basic_window', using the Makefile. This is useful for testing individual components. ```batch ::echo > Compile one specific example ::$(MAKE) core/core_basic_window PLATFORM=$(PLATFORM) -B ``` -------------------------------- ### Compile a specific raylib example Source: https://github.com/raysan5/raylib/wiki/Working-on-Chrome-OS Compiles a single raylib example, 'core/core_basic_window', for desktop platforms. ```bash make core/core_basic_window PLATFORM=PLATFORM_DESKTOP ``` -------------------------------- ### Example Executable Creation and Linking Source: https://github.com/raysan5/raylib/blob/master/examples/CMakeLists.txt Iterates through example sources, creates an executable for each, and links the raylib library. Also links the 'm' library on non-Windows systems. ```cmake foreach (example_source ${example_sources}) # Create the basename for the example get_filename_component(example_name ${example_source} NAME) string(REPLACE ".c" "" example_name ${example_name}) # Setup the example add_executable(${example_name} ${example_source}) target_link_libraries(${example_name} raylib) if (NOT WIN32) target_link_libraries(${example_name} m) endif() string(REGEX MATCH ".*/.*/" resources_dir ${example_source}) string(APPEND resources_dir "resources") if (${PLATFORM} MATCHES "Web") target_compile_options(${example_name} PRIVATE -Os) target_link_options(${example_name} PRIVATE -sALLOW_MEMORY_GROWTH=1 -sEXPORTED_RUNTIME_METHODS=[requestFullscreen] -sUSE_GLFW=3 --shell-file "${CMAKE_SOURCE_DIR}/src/shell.html" ) set_target_properties(${example_name} PROPERTIES SUFFIX ".html") if (EXISTS ${resources_dir}) # The local resources path needs to be mapped to /resources virtual path string(APPEND resources_dir "@resources") set_target_properties(${example_name} PROPERTIES LINK_FLAGS "--preload-file ${resources_dir}") endif () if(${GRAPHICS} MATCHES "GRAPHICS_API_OPENGL_ES3") target_link_options(${example_name} PUBLIC "-sMIN_WEBGL_VERSION=2") target_link_options(${example_name} PUBLIC "-sMAX_WEBGL_VERSION=2") endif() # Checks if OSX and links appropriate frameworks (Only required on MacOS) if (APPLE) target_link_libraries(${example_name} "-framework IOKit") target_link_libraries(${example_name} "-framework Cocoa") target_link_libraries(${example_name} "-framework OpenGL") endif() elseif (${PLATFORM} MATCHES "RGFW") if (APPLE) target_link_libraries(${example_name} "-framework IOKit") target_link_libraries(${example_name} "-framework Cocoa") target_link_libraries(${example_name} "-framework OpenGL") elseif (WIN32) target_link_libraries(${example_name} "-lgdi32") target_link_libraries(${example_name} "-lwinmm") elseif (UNIX) target_link_libraries(${example_name} "-lX11") target_link_libraries(${example_name} "-lXrandr") endif() endif () endforeach() ``` -------------------------------- ### Install X11 and Xorg development libraries Source: https://github.com/raysan5/raylib/wiki/Working-on-Chrome-OS Installs the necessary development headers for X11 and Xorg, required for graphical applications on Linux. ```bash sudo apt install libx11-dev xorg-dev ``` -------------------------------- ### Install static raylib library Source: https://github.com/raysan5/raylib/wiki/Working-on-Chrome-OS Installs the compiled static raylib library to standard system directories. ```bash sudo make install ``` -------------------------------- ### Generate Pkg-Config and Install Targets Source: https://github.com/raysan5/raylib/blob/master/src/external/glfw/src/CMakeLists.txt Constructs pkg-config files and defines installation rules for the library targets. ```cmake foreach(arg ${glfw_PKG_DEPS}) string(APPEND deps " ${arg}") endforeach() foreach(arg ${glfw_PKG_LIBS}) string(APPEND libs " ${arg}") endforeach() set(GLFW_PKG_CONFIG_REQUIRES_PRIVATE "${deps}" CACHE INTERNAL "GLFW pkg-config Requires.private") set(GLFW_PKG_CONFIG_LIBS_PRIVATE "${libs}" CACHE INTERNAL "GLFW pkg-config Libs.private") configure_file("${GLFW_SOURCE_DIR}/CMake/glfw3.pc.in" glfw3.pc @ONLY) if (GLFW_INSTALL) install(TARGETS glfw EXPORT glfwTargets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") endif() ``` -------------------------------- ### Build ONE Raylib Example with GCC/G++ Source: https://github.com/raysan5/raylib/wiki/Working-on-Windows Compile a single example file using GCC/G++ within w64devkit. This command links against raylib and necessary Windows libraries. ```bash gcc core_basic_window.c -lraylib -lgdi32 -lwinmm ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/raysan5/raylib/wiki/Working-on-macOS Install the necessary command line tools for development on macOS. ```bash xcode-select --install ``` -------------------------------- ### Install raylib development files on openSUSE Source: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux Install the raylib development package on openSUSE using zypper. Includes adding a repository if necessary. ```bash zypper in raylib-devel ``` ```bash zypper ar -f http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_Factory/devel:libraries:c_c++.repo zypper ref zypper in raylib-devel ``` -------------------------------- ### Collect Example Source Files and Resources Source: https://github.com/raysan5/raylib/blob/master/examples/CMakeLists.txt This snippet iterates through example directories to gather all .c source files and resource files. It appends these to respective CMake lists. ```cmake set(example_sources) set(example_resources) foreach (example_dir ${example_dirs}) # Get the .c files file(GLOB sources ${example_dir}/*.c) list(APPEND example_sources ${sources}) # Any any resources file(GLOB resources ${example_dir}/resources/*) list(APPEND example_resources ${resources}) endforeach () ``` -------------------------------- ### Build and install GLFW from source Source: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux Download, extract, and build GLFW version 3.4 from source using CMake. Installs GLFW to the system. ```bash wget https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.zip unzip glfw-3.4.zip cd glfw-3.4 cmake . sudo make install ``` -------------------------------- ### Install raylib on Arch Linux Source: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux Install the raylib package from the official Arch Linux repository using pacman. ```bash pacman -S raylib ``` -------------------------------- ### Compile Specific Example (Web Shader Deferred Render) Source: https://github.com/raysan5/raylib/blob/master/projects/Notepad++/npes_saved_w64devkit.txt Compiles a specific example, 'shaders/shader_deferred_render', using a custom Web Makefile. This is for web-specific compilation. ```batch ::echo > Compile one specific example, using Web custom Makefile.Web ::$(MAKE) -f Makefile.Web shaders/shaders_deferred_render PLATFORM=$(PLATFORM) -B ``` -------------------------------- ### Build ONE Raylib Example with MSVC/CL Source: https://github.com/raysan5/raylib/wiki/Working-on-Windows Compile a single example file using the MSVC compiler (cl). This command specifies include and library paths for Raylib and links required libraries. ```bash cl gdi32.lib msvcrt.lib raylib.lib winmm.lib user32.lib shell32.lib filename.c -Ic:\path\to\raylib\include /link /libpath:c:\path\to\raylib\lib /NODEFAULTLIB:libcmt /NODEFAULTLIB:msvcrtd ``` -------------------------------- ### Install Dependencies and Build fbcp-ili9341 Source: https://github.com/raysan5/raylib/wiki/Using-SPI-Displays-with-raylib Installs required packages and builds the fbcp-ili9341 software for SPI display communication. Ensure you are in the correct directory before running. ```bash sudo apt install git cmake p7zip-full libraspberrypi-dev libvcos-dev libvchiq-dev -y cd ~ git clone https://github.com/juj/fbcp-ili9341.git cd fbcp-ili9341 mkdir build cd build cmake -DSPI_BUS_CLOCK_DIVOR=20 -DWAVESHARE_ST7735S_HAT=ON -DBACKLIGHT_CONTROL=OFF -DSTATISTICS=0 -DDISPLAY_SWAP_BGR=ON .. make -j ``` -------------------------------- ### Build raylib examples with CMake custom build Source: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux Enable custom build options and examples when building from the 'raylib/examples' directory using CMake. ```bash cmake -DCUSTOMIZE_BUILD=ON -DBUILD_EXAMPLES=ON .. make ``` -------------------------------- ### rexm: raylib Examples Manager Usage Source: https://github.com/raysan5/raylib/blob/master/HISTORY.md The 'rexm' tool simplifies the management of raylib examples, offering commands for creation, addition, renaming, removal, building, testing, and validation. ```bash USAGE: > rexm [] COMMANDS: create : Creates an empty example, from internal template add : Add existing example to collection rename : Rename an existing example remove : Remove an existing example from collection build : Build example for Desktop and Web platforms test : Build and Test example for Desktop and Web platforms validate : Validate examples collection, generates report update : Validate and update examples collection, generates report ``` -------------------------------- ### Initial Project Setup Commands Source: https://github.com/raysan5/raylib/wiki/Working-for-Android-(on-macOS) Sets up the project directory by creating necessary subdirectories, copying the raylib static library, and placing icon files into the appropriate resource directories. ```bash cd project1 mkdir lib/arm64-v8a cp ../raylib/src/libraylib.a lib/arm64-v8a/libraylib.a cp ../raylib/logo/raylib_72x72.png res/drawable-hdpi/icon.png cp ../raylib/logo/raylib_36x36.png res/drawable-ldpi/icon.png cp ../raylib/logo/raylib_48x48.png res/drawable-mdpi/icon.png cp ../raylib/logo/raylib_96x96.png res/drawable-xhdpi/icon.png keytool -genkeypair -validity 1000 -dname "CN=seth,O=Android,C=ES" -keystore project.keystore -storepass 'mypass' -keypass 'mypass' -alias projectKey -keyalg RSA ``` -------------------------------- ### List of Files to Manage for Raylib Examples Source: https://github.com/raysan5/raylib/blob/master/tools/rexm/README.md This list details the files that need to be managed when adding or modifying a raylib example. It covers source files, resources, build configurations, and web deployment assets. ```text - Add: raylib/examples//_example_name.c - Add: raylib/examples//_example_name.png - Add: raylib/examples//resources/.. - Edit: raylib/examples/Makefile - Edit: raylib/examples/Makefile.Web - Add: raylib/projects/VS2022/examples/_example_name.vcxproj - Edit: raylib/projects/VS2022/raylib.sln - Edit: raylib/examples/README.md - Edit: raylib.com/common/examples.js - Generate: raylib.com/examples//_example_name.html - Generate: raylib.com/examples//_example_name.data - Generate: raylib.com/examples//_example_name.wasm - Generate: raylib.com/examples//_example_name.js ``` -------------------------------- ### Play Sound Example Source: https://github.com/raysan5/raylib/blob/master/examples/README.md Demonstrates basic sound loading and playing. Requires a sound file to be loaded. ```c #include "raylib.h" int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [audio] example - basic sound playing"); // Load sound Sound fxBeep = LoadSound("resources/audio/beep.ogg"); // Requires beep.ogg in resources/audio folder SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsKeyPressed(KEY_SPACE)) { PlaySound(fxBeep); // Play sound effect } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("Press SPACE to play the beep sound", 200, 200, 20, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadSound(fxBeep); // Unload sound from memory CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } ``` -------------------------------- ### CPack Installer Configuration Source: https://github.com/raysan5/raylib/blob/master/src/CMakeLists.txt Includes CPack configurations for creating installers. Ensure PackConfigurations module is available for installer generation. ```cmake # Options if you want to create an installer using CPack include(PackConfigurations) ``` -------------------------------- ### Manage fbcp service Source: https://github.com/raysan5/raylib/wiki/Using-SPI-Displays-with-raylib Commands to enable, start, and debug the fbcp service. ```bash sudo systemctl enable fbcp.service sudo systemctl start fbcp.service sudo reboot ``` ```bash sudo systemctl stop fbcp.service /home/lime-dev/fbcp-ili9341/build/fbcp-ili9341 ``` -------------------------------- ### Start Local Web Server with Python Source: https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5) Use this command to serve the compiled web files locally for testing. ```bash python -m http.server 8080 ``` -------------------------------- ### Create a basic window Source: https://github.com/raysan5/raylib/blob/master/examples/README.md Demonstrates the fundamental steps to initialize a raylib window and manage its basic lifecycle. ```c #include "raylib.h" int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } ``` -------------------------------- ### Install GLFW CMake Configuration Files Source: https://github.com/raysan5/raylib/blob/master/src/external/glfw/CMakeLists.txt Installs the CMake configuration files for GLFW, which are necessary for other projects to find and link against the installed GLFW library using CMake. ```cmake install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" DESTINATION "${GLFW_CONFIG_PATH}") ``` -------------------------------- ### Install GLFW Header Files Source: https://github.com/raysan5/raylib/blob/master/src/external/glfw/CMakeLists.txt Installs the GLFW header files to the system's include directory. This ensures that projects can find and include GLFW headers after installation. ```cmake install(DIRECTORY include/GLFW DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h) ``` -------------------------------- ### Reinstall raylib Source: https://github.com/raysan5/raylib/wiki/Working-on-macOS Reinstall raylib if pkg-config was installed after the initial raylib installation. ```bash brew reinstall raylib ``` -------------------------------- ### Compile and run with GCC Source: https://github.com/raysan5/raylib/wiki/Working-on-Windows Commands to compile the hello world example and execute the resulting binary in the w64devkit console. ```bash gcc -o raylibhelloworld.exe raylibhelloworld.c -I include -L lib -lraylib -lgdi32 -lwinmm ``` ```bash ./raylibhelloworld.exe ``` -------------------------------- ### Install Dependencies on macOS Source: https://github.com/raysan5/raylib/wiki/Using-raylib-in-VSCode Commands to install CMake and Raylib using Homebrew. ```bash brew install cmake ``` ```bash brew install raylib ``` -------------------------------- ### Example Makefile Configuration for Linux/macOS Source: https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5) A sample configuration for the Makefile showing how to define paths for the Emscripten toolchain. ```makefile EMSDK_PATH ?= /path/to/emsdk EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/upstream/emscripten CLANG_PATH = $(EMSDK_PATH)/upstream/bin PYTHON_PATH = /path/to/python NODE_PATH = $(EMSDK_PATH)/node/12.9.1_64bit/bin PATH = $(shell printenv PATH):$(EMSDK_PATH):$(EMSCRIPTEN_PATH):$(CLANG_PATH):$(NODE_PATH):$(PYTHON_PATH) ``` -------------------------------- ### Conditional Inclusion of Physac Example Source: https://github.com/raysan5/raylib/blob/master/examples/CMakeLists.txt Conditionally adds the 'physac' directory to the list of example directories if either HAVE_QPC or HAVE_CLOCK_MONOTONIC is true. This ensures the physac example is only built when its required system functionalities are present. ```cmake if (HAVE_QPC OR HAVE_CLOCK_MONOTONIC) set(example_dirs ${example_dirs} physac) endif () ``` -------------------------------- ### Stream Music Example Source: https://github.com/raysan5/raylib/blob/master/examples/README.md Demonstrates streaming music playback. Requires a music file to be loaded. ```c #include "raylib.h" int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [audio] example - music stream"); // Load music Music music = LoadMusicStream("resources/audio/music.ogg"); // Requires music.ogg in resources/audio folder PlayMusicStream(music); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- UpdateMusicStream(music); // Update music buffer with new stream data // Pause/Resume music if (IsKeyPressed(KEY_P)) { if (IsMusicStreamPlaying(music)) PauseMusicStream(music); else ResumeMusicStream(music); } // Stop/Start music if (IsKeyPressed(KEY_S)) { StopMusicStream(music); // Re-stream music from beginning // PlayMusicStream(music); } // Change pitch if (IsKeyPressed(KEY_UP)) { float pitch = GetMusicTimeLength(music) / GetMusicTimePlayed(music); SetMusicPitch(music, pitch + 0.1f); } if (IsKeyPressed(KEY_DOWN)) { float pitch = GetMusicTimeLength(music) / GetMusicTimePlayed(music); SetMusicPitch(music, pitch - 0.1f); } // Loop music if (IsKeyPressed(KEY_L)) { if (IsMusicStreamLooping(music)) SetMusicLooping(music, false); else SetMusicLooping(music, true); } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); if (IsMusicStreamPlaying(music)) DrawText("MUSIC IS PLAYING", 200, 200, 20, LIGHTGRAY); else DrawText("PRESS P TO PLAY/PAUSE", 200, 200, 20, GRAY); DrawText("PRESS P TO PLAY/PAUSE MUSIC", 180, 140, 20, LIGHTGRAY); DrawText("PRESS S TO STOP MUSIC", 180, 180, 20, LIGHTGRAY); DrawText("PRESS UP/DOWN TO CHANGE PITCH", 180, 220, 20, LIGHTGRAY); DrawText("PRESS L TO TOGGLE LOOPING", 180, 260, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadMusicStream(music); // Unload music stream from memory CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } ``` -------------------------------- ### Find and Link Raylib with CMake Source: https://github.com/raysan5/raylib/wiki/Working-with-CMake Use this CMake configuration to find an installed raylib (version 3.0 or higher) and link it to your C11 project. Ensure raylib is installed via a package manager or 'make install'. ```cmake cmake_minimum_required(VERSION 3.15) project(my_project) find_package(raylib 3.0 REQUIRED) # Requires at least version 3.0 set(CMAKE_C_STANDARD 11) # Requires C11 standard add_executable(${PROJECT_NAME} main.c) target_link_libraries(${PROJECT_NAME} raylib) # Checks if OSX and links appropriate frameworks (only required on MacOS) if (APPLE) target_link_libraries(${PROJECT_NAME} "-framework IOKit") target_link_libraries(${PROJECT_NAME} "-framework Cocoa") target_link_libraries(${PROJECT_NAME} "-framework OpenGL") endif() ``` -------------------------------- ### Basic raylib Hello World Source: https://github.com/raysan5/raylib/wiki/Working-on-Windows A minimal C program to initialize a window and render text using raylib. ```c #include "raylib.h" int main() { const int screenWidth = 800; const int screenHeight = 600; InitWindow(screenWidth, screenHeight, "raylib basic window"); SetTargetFPS(60); while (!WindowShouldClose()) { BeginDrawing(); ClearBackground(RAYWHITE); DrawText("It works!", 20, 20, 20, BLACK); EndDrawing(); } CloseWindow(); return 0; } ``` -------------------------------- ### Install CMake build system Source: https://github.com/raysan5/raylib/wiki/Working-on-Chrome-OS Installs CMake, an alternative cross-platform build system generator. ```bash sudo apt install cmake ``` -------------------------------- ### Install dependencies for SPI Source: https://github.com/raysan5/raylib/wiki/Using-SPI-Displays-with-raylib Install required packages for building raylib and SPI support on the system. ```bash # Definitly needed sudo apt install xvfb build-essential git cmake # Some of these may not be needed and can be skipped. sudo apt install xorg-dev libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxfixes-dev sudo apt install libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev sudo apt install libdrm-dev libgbm-dev sudo apt install libasound2-dev libglu1-mesa-dev libwayland-dev libxkbcommon-dev sudo apt-get install raspberrypi-ui-mods lxterminal gvfs sudo apt-get install mesa-common-dev sudo apt-get install wayland-protocols ``` -------------------------------- ### Setup Web Compilation Environment Source: https://github.com/raysan5/raylib/blob/master/projects/Notepad++/npes_saved_w64devkit.txt Sets up the necessary environment variables for compiling Raylib for the web. This includes paths to the Raylib source, Emscripten SDK, and related tools. ```shell echo "> Setup required Environment" echo "--------------------------------------------------" SET RAYLIB_PATH=C:\raylib\raylib SET EMSDK_PATH=C:\raylib\emsdk SET EMSCRIPTEN_PATH=$(EMSDK_PATH)\upstream\emscripten SET CLANG_PATH=$(EMSDK_PATH)\upstream\emscripten SET PYTHON_PATH=$(EMSDK_PATH)\python\3.10.2_64bit SET NODE_PATH=$(EMSDK_PATH)\node\20.5.0_64bit\bin ENV_SET PATH=$(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH) ``` -------------------------------- ### Build raylib from Source Source: https://github.com/raysan5/raylib/wiki/Working-on-macOS Navigate to the source directory and compile the library using make. ```bash cd raylib-master/src ``` ```bash make PLATFORM=PLATFORM_DESKTOP ``` -------------------------------- ### Install DietPi Build Dependencies Source: https://github.com/raysan5/raylib/wiki/Working-on-Raspberry-Pi Install essential libraries and headers for building raylib on the DietPi distribution. ```bash sudo apt-get install libraspberrypi-dev raspberrypi-kernel-headers sudo apt-get install build-essential ``` -------------------------------- ### Compile Project with Meson Source: https://github.com/raysan5/raylib/blob/master/projects/Builder/README.md Instructions for compiling the project from the command line using Meson, Ninja, and Ninja install. ```bash meson build cd build ninja ninja install ``` -------------------------------- ### 2D Camera System Example Source: https://github.com/raysan5/raylib/blob/master/HISTORY.md Demonstrates the usage of the 2D camera system. This snippet shows how to set up and manipulate a camera for 2D scrolling and view. ```c #include "raylib.h" int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera system"); // Define the camera to look into our 2d world Camera2D camera = { 0 }; camera.target = (Vector2){ (float)screenWidth/2, (float)screenHeight/2 }; camera.offset = (Vector2){ screenWidth/2, screenHeight/2 }; camera.rotation = 0.0f; camera.zoom = 1.0f; Vector2 playerPosition = { (float)screenWidth/2, (float)screenHeight/2 }; SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // Player movement if (IsKeyDown(KEY_RIGHT)) playerPosition.x += 2.0f; if (IsKeyDown(KEY_LEFT)) playerPosition.x -= 2.0f; if (IsKeyDown(KEY_UP)) playerPosition.y -= 2.0f; if (IsKeyDown(KEY_DOWN)) playerPosition.y += 2.0f; // Camera modification // Zoom camera.zoom += GetMouseWheelMove() * 0.05f; if (camera.zoom > 3.0f) camera.zoom = 3.0f; if (camera.zoom < 0.1f) camera.zoom = 0.1f; // Rotation if (IsKeyDown(KEY_R)) camera.rotation -= 1.0f; if (IsKeyDown(KEY_E)) camera.rotation += 1.0f; // Camera target // NOTE: Camera target is calculated using player position and camera offset camera.target = playerPosition; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); BeginMode2D(camera); // Draw world elements DrawRectangle(-1000, -1000, 2000, 2000, LIGHTGRAY); // Draw a big rectangle DrawCircleV(playerPosition, 30, RED); // Draw player DrawRectangleLines(playerPosition.x - 40, playerPosition.y - 40, 80, 80, DARKGRAY); // Draw player bounding box // Draw circle at origin DrawCircle(0, 0, 10, DARKBLUE); EndMode2D(); DrawRectangle(0, 0, screenWidth, 10, BLACK); // Top bar DrawText("- MOVE PLAYER WITH KEYS - ESCAPE TO EXIT", 120, 20, 20, BLACK); DrawText("USE MOUSE WHEEL TO ZOOM", 10, 40, 10, DARKGRAY); DrawText("USE KEYS R/E TO ROTATE", 10, 60, 10, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } ``` -------------------------------- ### Basic C++ Compilation Setup Source: https://github.com/raysan5/raylib/blob/master/projects/Notepad++/npes_saved_w64devkit.txt Sets up the environment for basic C++ compilation using g++. This includes setting paths and defining the compiler. ```batch ::basic_cpp_compilation echo echo > Setup required Environment echo -------------------------------------------------- SET RAYLIB_PATH=C:\raylib\raylib SET COMPILER_PATH=C:\raylib\w64devkit\bin ENV_SET PATH=$(COMPILER_PATH) SET CC=g++ cd $(CURRENT_DIRECTORY) echo echo > Saving Current File ``` -------------------------------- ### List available Android SDK packages Source: https://github.com/raysan5/raylib/wiki/Working-for-Android Run this command to view all installable versions and API levels available through the sdkmanager. ```bash sdkmanager --sdk_root= --list ``` -------------------------------- ### Install tslib build dependencies Source: https://github.com/raysan5/raylib/wiki/Install-and-configure-Touchscreen-Drivers-(RPi) Installs automake and libtool, which are required to build tslib on a Raspberry Pi. ```bash sudo apt-get install automake libtool ``` -------------------------------- ### Build and install raylib using make Source: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux Commands to clone the repository and compile either static or dynamic versions of the library. ```bash git clone --depth 1 https://github.com/raysan5/raylib.git raylib cd raylib/src/ make PLATFORM=PLATFORM_DESKTOP # To make the static version. make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED # To make the dynamic shared version. ``` ```bash sudo make install # Static version. sudo make install RAYLIB_LIBTYPE=SHARED # Dynamic shared version. sudo make uninstall sudo make uninstall RAYLIB_LIBTYPE=SHARED ``` -------------------------------- ### Install tslib package Source: https://github.com/raysan5/raylib/wiki/Install-and-configure-Touchscreen-Drivers-(RPi) Installs the tslib package, which provides the necessary libraries and tools for touchscreen input handling. ```bash sudo apt-get install ts-lib ``` -------------------------------- ### Raylib Logo Animation Example Source: https://github.com/raysan5/raylib/blob/master/examples/README.md Animates the Raylib logo. This example demonstrates sprite animation and basic timing. ```c #include "raylib.h" int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [shapes] example - logo raylib anim"); // NOTE: Textures MUST be loaded after Window is initialized. Texture2D logo = LoadTexture("resources/raylib_icon.png"); Vector2 position = { screenWidth/2.0f - logo.width/2.0f, screenHeight/2.0f - logo.height/2.0f }; float rotation = 0.0f; float scale = 1.0f; Color tint = WHITE; // Draw color SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- rotation += 1.0f; // Rotate the logo 1 degree per frame scale += 0.01f; // Increase the scale // Reset rotation and scale if they exceed their limits if (scale > 2.0f) { scale = 1.0f; rotation = 0.0f; } // Change tint color based on time tint = (Color){ (unsigned char)(255.0f * sinf(GetTime() * 2.0f)), (unsigned char)(255.0f * cosf(GetTime() * 2.0f)), (unsigned char)(255.0f * sinf(GetTime() * 1.0f)), 255 }; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawTextureEx(logo, position, rotation, scale, tint); DrawText("Use arrow keys to control", 10, 10, 20, DARKGRAY); DrawText("rotation and scale", 10, 40, 20, DARKGRAY); DrawText("Press SPACE to reset", 10, 70, 20, DARKGRAY); DrawFPS(screenWidth - 90, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadTexture(logo); // Unload texture from GPU memory CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } ``` -------------------------------- ### Install raylib runtime library on Debian Source: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux Install only the raylib runtime library on Debian (version 550) using apt. ```bash sudo apt install libraylib550 ``` -------------------------------- ### Compile raylib from source Source: https://github.com/raysan5/raylib/wiki/Compile-for-OSX Build the raylib library for the desktop platform using the make utility. ```bash make PLATFORM=PLATFORM_DESKTOP ``` -------------------------------- ### MSYS2 Package Installation Commands Source: https://github.com/raysan5/raylib/wiki/Working-for-Android Commands to install necessary toolchains and make within the MSYS2 environment for Android development. ```bash pacman -S mingw-w64-i686-toolchain (select default 选择默认的) pacman -S mingw-w64-x86_64-make ``` -------------------------------- ### Project Setup and Versioning Source: https://github.com/raysan5/raylib/blob/master/src/CMakeLists.txt Initializes the CMake project for raylib, setting the project name, language, and version information. ```cmake project(raylib C) set(PROJECT_VERSION 6.0.0) set(API_VERSION 600) ``` -------------------------------- ### Build APK Command Source: https://github.com/raysan5/raylib/wiki/Working-for-Android Use mingw32-make with PLATFORM=PLATFORM_ANDROID to build the APK. ```bash mingw32-make PLATFORM=PLATFORM_ANDROID ``` -------------------------------- ### Install APK using ADB Source: https://github.com/raysan5/raylib/wiki/Working-for-Android Command to install the compiled APK onto a connected Android device using ADB. ```bash %ANDROID_SDK_TOOLS%\adb install simple_game.apk ``` -------------------------------- ### Configure Environment and Execute Makefile Source: https://github.com/raysan5/raylib/blob/master/projects/Notepad++/npes_saved_tcc.txt Sets up the platform and path variables required to build raylib projects using a Makefile. ```batch ::raylib_makefile echo > Choose compile options echo ------------------------------- echo Set desired PLATFORM: DESKTOP, RPI, ANDROID, WEB SET PLATFORM=PLATFORM_DESKTOP echo echo > Setup required Environment echo ----------------------------------- SET RAYLIB_PATH=C:\raylib\raylib SET COMPILER_PATH=C:\raylib\tcc ENV_SET PATH=$(COMPILER_PATH) SET MAKE=make cd $(CURRENT_DIRECTORY) echo echo WARNING: Makefile to be executed must be open and selected! echo echo > Execute makefile echo ----------------------- //$(MAKE) clean $(MAKE) PLATFORM=$(PLATFORM) -B // Build a single example using raylib/examples/Makefile //$(MAKE) core/core_basic_window PLATFORM=$(PLATFORM) -B echo echo > Reset Environment echo ----------------------- ENV_UNSET PATH ``` -------------------------------- ### Install dynamic shared raylib library Source: https://github.com/raysan5/raylib/wiki/Working-on-Chrome-OS Installs the compiled dynamic shared raylib library to standard system directories. ```bash sudo make install RAYLIB_LIBTYPE=SHARED ``` -------------------------------- ### Inspect Application Linker Information Source: https://github.com/raysan5/raylib/wiki/Compile-for-OSX Use otool -L to list all dynamic libraries that your application links against. Verify that there are no dependencies on non-standard paths to ensure portability. ```bash otool -L my_app ``` -------------------------------- ### Install Android NDK via sdkmanager Source: https://github.com/raysan5/raylib/wiki/Working-for-Android Use this command to install a specific version of the Android Native Development Kit. ```bash sdkmanager --sdk_root= --install ndk; ``` -------------------------------- ### Get Key Pressed Function Source: https://github.com/raysan5/raylib/wiki/raylib-syntax-analysis Use GetKeyPressed to retrieve the last key pressed. This function is part of the get group. ```c GetKeyPressed() ``` -------------------------------- ### Install GLFW Pkgconfig File Source: https://github.com/raysan5/raylib/blob/master/src/external/glfw/CMakeLists.txt Installs the pkgconfig file for GLFW, enabling integration with systems that use pkgconfig for managing libraries. ```cmake install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") ``` -------------------------------- ### Install raylib development files on Debian Source: https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux Install the raylib development package on Debian (14 'Forky' or unstable) using apt. ```bash sudo apt install libraylib-dev ```