Integrate PhysFS with raylib, allowing to load images, audio and fonts from data archives.

raylib-physfs

Integrate the virtual file system PhysicsFS with raylib, allowing to load images, audio, and fonts from data archives.

Features

  • Load the following data from archives
    • Images with LoadImageFromPhysFS()
    • Textures with LoadTextureFromPhysFS()
    • Music with LoadMusicStreamFromPhysFS()
    • Waves with LoadWaveFromPhysFS()
    • Fonts with LoadFontFromPhysFS()
    • Text with LoadFileTextFromPhysFS()
    • Shaders with LoadShaderFromPhysFS()
  • Check if directories and files exist
  • Enumerate across multiple archives and mount paths
  • Save files through PhysFS
  • Set all file loading to use PhysFS with SetPhysFSCallbacks()

Usage

This is a single-file header. To use it, define RAYLIB_PHYSFS_IMPLEMENTATION in one .c source file before including raylib-physfs.h. You will also have to link the PhysFS and raylib dependencies.

Example

#define RAYLIB_PHYSFS_IMPLEMENTATION
#include "raylib-physfs.h"

int main() {
    // Initiatize the file system.
    InitPhysFS();

    // Mount a directory or archive.
    MountPhysFS("assets.zip", "assets");

    // Load an image through PhysFS.
    Image dog = LoadImageFromPhysFS("assets/dog.png");

    // Close the file system.
    ClosePhysFS();
}

Cheatsheet

bool InitPhysFS();                                              // Initialize the PhysFS file system
bool ClosePhysFS();                                             // Close the PhysFS file system
bool IsPhysFSReady();                                           // Check if PhysFS has been initialized successfully
bool MountPhysFS(const char* newDir, const char* mountPoint);   // Mount the given directory or archive as a mount point
bool MountPhysFSFromMemory(const unsigned char *fileData, int dataSize, const char* newDir, const char* mountPoint);  // Mount the given file data as a mount point
bool UnmountPhysFS(const char* oldDir);                         // Unmounts the given directory
bool FileExistsInPhysFS(const char* fileName);                  // Check if the given file exists in PhysFS
bool DirectoryExistsInPhysFS(const char* dirPath);              // Check if the given directory exists in PhysFS
unsigned char* LoadFileDataFromPhysFS(const char* fileName, unsigned int* bytesRead);  // Load a data buffer from PhysFS (memory should be freed)
char* LoadFileTextFromPhysFS(const char* fileName);             // Load text from a file (memory should be freed)
bool SetPhysFSWriteDirectory(const char* newDir);               // Set the base directory where PhysFS should write files to (defaults to the current working directory)
bool SaveFileDataToPhysFS(const char* fileName, void* data, unsigned int bytesToWrite);  // Save the given file data in PhysFS
bool SaveFileTextToPhysFS(const char* fileName, char* text);    // Save the given file text in PhysFS
char** GetDirectoryFilesFromPhysFS(const char* dirPath, int* count);  // Get filenames in a directory path (memory should be freed)
void ClearDirectoryFilesFromPhysFS(char** filesList);           // Clear directory files paths buffers (free memory)
long GetFileModTimeFromPhysFS(const char* fileName);            // Get file modification time (last write time) from PhysFS
Image LoadImageFromPhysFS(const char* fileName);                // Load an image from PhysFS
Texture2D LoadTextureFromPhysFS(const char* fileName);          // Load a texture from PhysFS
Wave LoadWaveFromPhysFS(const char* fileName);                  // Load wave data from PhysFS
Music LoadMusicStreamFromPhysFS(const char* fileName);          // Load music data from PhysFS
Font LoadFontFromPhysFS(const char* fileName, int fontSize, int *fontChars, int charsCount);  // Load a font from PhysFS
Shader LoadShaderFromPhysFS(const char *vsFileName, const char *fsFileName);  // Load shader from PhysFS
void SetPhysFSCallbacks();                                      // Set the raylib file loader/saver callbacks to use PhysFS

Development

To build the examples locally, and run tests, use cmake.

git submodule update --init
mkdir build
cd build
cmake ..
make
make test
cd examples
./textures_image_loading

License

raylib-physfs is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check LICENSE for further details.

Similar Resources

Pong clone made in C++ with raylib

Raypong Pong clone made in C++ with raylib. Dependencies ...C++ and raylib lol Building To build, use these commands: mkdir build # Create a build dir

Feb 4, 2022

raylib Nuget package

raylib Nuget package This is a Nuget package for the popular raylib video game programming library. Resources used to create this package are as follo

Nov 18, 2022

Minimalistic assertion library for raylib.

raylib-assert Minimalistic assertion library for raylib. Example #include "raylib.h" #include "raylib-assert.h" int main(void) { Assert(10 == 10)

Jan 12, 2022

A top-down shooter made for the raylib 5K gamejam.

A top-down shooter made for the raylib 5K gamejam.

ANTISPELL Description A top-down shooter where you have to use your enemies' attacks to spell your spells! Features Absorb letters getting close to en

Apr 9, 2022

runsc loads 32/64 bit shellcode (depending on how runsc is compiled) in a way that makes it easy to load in a debugger. This code is based on the code from https://github.com/Kdr0x/Kd_Shellcode_Loader by Gary "kd" Contreras.

runsc This code is based on the code from https://github.com/Kdr0x/Kd_Shellcode_Loader by Gary "kd" Contreras and contains additional functionality. T

Nov 9, 2022

A simple application that generates animated BTTV emotes from static images

emoteJAM WARNING! The application is in active development and can't do anything yet. A simple application that generates animated BTTV emotes from st

Apr 27, 2021

This data is a sample data created for a Qiita article and a YouTube commentary.

This data is a sample data created for a Qiita article and a YouTube commentary.

NiagaraSample UE4 4.27.1 English This data is a sample data created for a Qiita article and a YouTube commentary. Here is some sample data that may be

Jun 15, 2022

Silk coder; Encode audio to silk; Decode silk to PCM

silk-codec A library for convert PCM to tencent silk files. Features Convert PCM to silk Convert audio to silk (FFMPEG required) Convert silk to PCM P

Nov 14, 2022

A C library for parsing/normalizing street addresses around the world. Powered by statistical NLP and open geo data.

A C library for parsing/normalizing street addresses around the world. Powered by statistical NLP and open geo data.

libpostal: international street address NLP libpostal is a C library for parsing/normalizing street addresses around the world using statistical NLP a

Nov 23, 2022
Comments
  • remove submodules, add full physfs

    remove submodules, add full physfs

    I had issues with miniphysfs building on mac, and noticed that the compiled size is roughly the same, depending on the options you use (for example disabling all but zip.) This PR shows an easy-to-build & simple alternative setup, using regular physfs, that pulls raylib & physfs from git (no submodules, just cmake config.)

    I find this kind of structure much more versatile, easier to use/setup, but I think for your lib it probly needs a bit more work to make it nicer for users (I'm not really exposing the lib correctly, just static building the demos.)

    WARNING: This is not really a drop-in replacement, as I wasn't quite sure how to structure the project to work well as a dep of user's projects. This is more of an example project that builds all the examples.

  • Add LoadDirectoryFilesFromPhysFS()

    Add LoadDirectoryFilesFromPhysFS()

    This change does a few things...

    • Remove GetDirectoryFilesFromPhysFS() and ClearDirectoryFilesFromPhysFS()
    • Add LoadDirectoryFilesFromPhysFS() returning a FilePathList. Make sure to UnloadDirectoryFiles.
    • Updates the CMake structure
    • Switches to raylib-assert for the tests
Load Aseprite files for animated sprites in raylib.
Load Aseprite files for animated sprites in raylib.

raylib-aseprite Load Aseprite .aseprite files for animated sprites in raylib. Features Load Aseprite files directly for use in raylib Draw individual

Oct 28, 2022
A Windows only library for allowing C++ to feel like C#

System What is this? C++ System is a header and Windows only library for interacting with the machine, in the way that C# does, but since C++ is not r

Nov 18, 2021
Utilities and common code for use with raylib

Utilities and shared components for use with raylib

Nov 18, 2022
Haxe bindings for raylib, a simple and easy-to-use library to learn videogame programming
Haxe bindings for raylib, a simple and easy-to-use library to learn videogame programming

Haxe bindings for raylib, a simple and easy-to-use library to learn videogame programming, Currently works only for windows but feel free the expand t

Nov 9, 2022
SWIG bindings for raylib (to Lua, and hopefully other languages)

swigraylib SWIG binding for raylib This repo generates raylib bindings to other languages (eg. Lua), by providing a raylib.i SWIG interface file. SWIG

Oct 28, 2021
autogen bindings to Raylib 4.0 and convenience wrappers on top. Requires use of `unsafe`

Raylib-CsLo Raylib-CsLo LowLevel autogen bindings to Raylib 4.0 and convenience wrappers on top. Requires use of unsafe A focus on performance. No run

Nov 13, 2022
My collection of raylib code examples - For learning the C language with 2D and 3D games.

Raylib-Examples My collection of raylib examples. ( https://www.raylib.com/index.html ) For Raylib Version of 4 april 2020 ( Notepad++ windows install

Sep 8, 2022
The Ultimate Raylib gaming library wrapper for Nim
The Ultimate Raylib gaming library wrapper for Nim

NimraylibNow! - The Ultimate Raylib wrapper for Nim The most idiomatic and up-to-date wrapper for Raylib gaming C library. Use this library if you wan

Nov 19, 2022
RayLib extern bindings for Haxe
RayLib extern bindings for Haxe

raylib-haxe Haxe bindings for RayLib usage haxelib git raylib-haxe https://github.com/haxeui/raylib-haxe package; import RayLib.*; import RayLib.Cam

Sep 9, 2022
A pong clone written in C++ with Raylib
A pong clone written in C++ with Raylib

How To Play Objective: first player to reach 10 points is the winner! PLAYER 1: W: up S: down PLAYER 2: ARROW UP or I: up ARROW DOWN or S: down Requir

Nov 8, 2021