Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to miniphysfs #5

Merged
merged 6 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Tests

on: [push, pull_request]

jobs:
Test:

runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Install Dependencies
run: sudo apt-get install xorg-dev libglu1-mesa-dev

- name: Configure
run: cmake -B build .

- name: Build
run: cmake --build build

- name: Test
run: ./build/test/raylib-physfs-test
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
path = vendor/physfs
url = https://github.com/icculus/physfs.git
ignore = dirty
[submodule "vendor/miniphysfs"]
path = vendor/miniphysfs
url = https://github.com/edubart/miniphysfs.git
ignore = dirty
24 changes: 15 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
cmake_minimum_required(VERSION 3.11)
project (raylib-physfs
VERSION 4.0.0
VERSION 4.0.1
DESCRIPTION "raylib-physfs"
HOMEPAGE_URL "https://github.com/robloach/raylib-physfs"
LANGUAGES C)
LANGUAGES C
)

# Include Directory
add_subdirectory(include)

# Static Library
option(BUILD_RAYLIB_PHYSFS_LIB "Library" ON)
if(BUILD_RAYLIB_PHYSFS_LIB)
add_subdirectory(lib)
endif()

# Examples
option(BUILD_RAYLIB_PHYSFS_EXAMPLES "Examples" ON)
if(BUILD_RAYLIB_PHYSFS_EXAMPLES)
add_subdirectory(examples)
endif()

# Testing
include(CTest)
enable_testing()
if(BUILD_TESTING AND BUILD_RAYLIB_PHYSFS_EXAMPLES)
set(CTEST_CUSTOM_TESTS_IGNORE
pkg-config--static
)
add_subdirectory(test)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
enable_testing()
if(BUILD_TESTING AND BUILD_RAYLIB_PHYSFS_LIB)
add_subdirectory(test)
endif()
endif()
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# raylib-physfs

Integrate the virtual file system [PhysicsFS](https://icculus.org/physfs/) with [raylib](https://www.raylib.com/), allowing to load images, audio, and fonts from data archives.
Integrate the virtual file system [PhysicsFS](https://icculus.org/physfs/) with [raylib](https://www.raylib.com/), allowing to load images, audio, and fonts from data archives. This uses [miniphysfs](https://github.com/edubart/miniphysfs) to reduce the dependency tree.

## Features

Expand All @@ -19,7 +19,7 @@ Integrate the virtual file system [PhysicsFS](https://icculus.org/physfs/) with

## Usage

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

### Example

Expand All @@ -31,7 +31,7 @@ int main() {
// Initiatize the file system.
InitPhysFS();

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

// Load an image through PhysFS.
Expand Down Expand Up @@ -76,12 +76,15 @@ Add these defines to help shape the behaviour of raylib-physfs...

- `RAYLIB_PHYSFS_IMPLEMENTATION` Define this in one of your `.c`/`.cpp` files prior to including *raylib-physfs.h*
- `RAYLIB_PHYSFS_STATIC` Use [`static`](https://en.wikipedia.org/wiki/Static_(keyword)) function definitions
- `PHYSFS_SUPPORTS_ONLY_ZIP` Only support .zip archives, rather than all the available ones.

## Development

To build the examples locally, and run tests, use [cmake](https://cmake.org/).

``` bash
git clone https://github.com/RobLoach/raylib-physfs.git
cd raylib-physfs
git submodule update --init
mkdir build
cd build
Expand All @@ -94,4 +97,4 @@ cd examples

## 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](LICENSE) for further details.
*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](LICENSE) for further details.
37 changes: 15 additions & 22 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Get the sources together
set(example_dirs audio text textures)
set(example_dirs audio shaders text textures)
set(example_sources)
set(example_resources)

Expand All @@ -11,26 +11,6 @@ if (NOT raylib_FOUND)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/raylib ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/raylib)
endif()

# PhysFS
find_package(physfs QUIET)
if (NOT physfs_FOUND)
set(PHYSFS_BUILD_STATIC ON CACHE BOOL "TRUE" FORCE)
set(PHYSFS_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(PTHREAD_LIBRARY OFF CACHE BOOL "" FORCE)
set(PHYSFS_ARCHIVE_ZIP OFF CACHE BOOL "" FORCE) # Enable PHYSFS_ARCHIVE_ZIP for .zip support
set(PHYSFS_ARCHIVE_7Z OFF CACHE BOOL "" FORCE)
set(PHYSFS_ARCHIVE_GRP OFF CACHE BOOL "" FORCE)
set(PHYSFS_ARCHIVE_WAD OFF CACHE BOOL "" FORCE)
set(PHYSFS_ARCHIVE_HOG OFF CACHE BOOL "" FORCE)
set(PHYSFS_ARCHIVE_MVL OFF CACHE BOOL "" FORCE)
set(PHYSFS_ARCHIVE_QPAK OFF CACHE BOOL "" FORCE)
set(PHYSFS_ARCHIVE_SLB OFF CACHE BOOL "" FORCE)
set(PHYSFS_ARCHIVE_ISO9660 OFF CACHE BOOL "" FORCE)
set(PHYSFS_ARCHIVE_VDF OFF CACHE BOOL "" FORCE)
set(PHYSFS_BUILD_TEST OFF CACHE BOOL "" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/physfs ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/physfs)
endif()

# Find all examples
foreach(example_dir ${example_dirs})
file(GLOB sources ${example_dir}/*.c)
Expand All @@ -51,7 +31,20 @@ foreach(example_source ${example_sources})
add_executable(${example_name} ${example_source})

# Link raylib and raylib-cpp
target_link_libraries(${example_name} PUBLIC raylib physfs-static raylib-physfs)
target_link_libraries(${example_name} PUBLIC raylib raylib-physfs)

target_compile_definitions(${example_name} PUBLIC
PHYSFS_SUPPORTS_NO_ZIP
PHYSFS_SUPPORTS_NO_7Z
PHYSFS_SUPPORTS_NO_GRP
PHYSFS_SUPPORTS_NO_WAD
PHYSFS_SUPPORTS_NO_HOG
PHYSFS_SUPPORTS_NO_MVL
PHYSFS_SUPPORTS_NO_QPAK
PHYSFS_SUPPORTS_NO_SLB
PHYSFS_SUPPORTS_NO_ISO9660
PHYSFS_SUPPORTS_NO_VDF
)

string(REGEX MATCH ".*/.*/" resources_dir ${example_source})
string(APPEND resources_dir "resources")
Expand Down
36 changes: 36 additions & 0 deletions examples/shaders/resources/shaders/glsl100/wave.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#version 100

precision mediump float;

// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;

// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;

uniform float secondes;

uniform vec2 size;

uniform float freqX;
uniform float freqY;
uniform float ampX;
uniform float ampY;
uniform float speedX;
uniform float speedY;

void main() {
float pixelWidth = 1.0 / size.x;
float pixelHeight = 1.0 / size.y;
float aspect = pixelHeight / pixelWidth;
float boxLeft = 0.0;
float boxTop = 0.0;

vec2 p = fragTexCoord;
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;

gl_FragColor = texture2D(texture0, p)*colDiffuse*fragColor;
}
37 changes: 37 additions & 0 deletions examples/shaders/resources/shaders/glsl330/wave.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#version 330

// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;

// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;

// Output fragment color
out vec4 finalColor;

uniform float secondes;

uniform vec2 size;

uniform float freqX;
uniform float freqY;
uniform float ampX;
uniform float ampY;
uniform float speedX;
uniform float speedY;

void main() {
float pixelWidth = 1.0 / size.x;
float pixelHeight = 1.0 / size.y;
float aspect = pixelHeight / pixelWidth;
float boxLeft = 0.0;
float boxTop = 0.0;

vec2 p = fragTexCoord;
p.x += cos((fragTexCoord.y - boxTop) * freqX / ( pixelWidth * 750.0) + (secondes * speedX)) * ampX * pixelWidth;
p.y += sin((fragTexCoord.x - boxLeft) * freqY * aspect / ( pixelHeight * 750.0) + (secondes * speedY)) * ampY * pixelHeight;

finalColor = texture(texture0, p)*colDiffuse*fragColor;
}
Binary file added examples/shaders/resources/space.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions examples/shaders/shaders_texture_waves.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*******************************************************************************************
*
* raylib [shaders] example - Texture Waves
*
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
*
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
* raylib comes with shaders ready for both versions, check raylib/shaders install folder
*
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Example contributed by Anata (@anatagawa) and reviewed by Ramon Santamaria (@raysan5)
*
* Copyright (c) 2019 Anata (@anatagawa) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/

#include "raylib.h"

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

#if defined(PLATFORM_DESKTOP)
#define GLSL_VERSION 330
#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
#define GLSL_VERSION 100
#endif

int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;

InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture waves");

// Initialize the file system, and mount a directory.
InitPhysFS();
MountPhysFS("resources", "res");

// Load texture texture to apply shaders
Texture2D texture = LoadTextureFromPhysFS("res/space.png");

// Load shader and setup location points and values
Shader shader = LoadShaderFromPhysFS(0, TextFormat("res/shaders/glsl%i/wave.fs", GLSL_VERSION));

int secondsLoc = GetShaderLocation(shader, "secondes");
int freqXLoc = GetShaderLocation(shader, "freqX");
int freqYLoc = GetShaderLocation(shader, "freqY");
int ampXLoc = GetShaderLocation(shader, "ampX");
int ampYLoc = GetShaderLocation(shader, "ampY");
int speedXLoc = GetShaderLocation(shader, "speedX");
int speedYLoc = GetShaderLocation(shader, "speedY");

// Shader uniform values that can be updated at any time
float freqX = 25.0f;
float freqY = 25.0f;
float ampX = 5.0f;
float ampY = 5.0f;
float speedX = 8.0f;
float speedY = 8.0f;

float screenSize[2] = { (float)GetScreenWidth(), (float)GetScreenHeight() };
SetShaderValue(shader, GetShaderLocation(shader, "size"), &screenSize, SHADER_UNIFORM_VEC2);
SetShaderValue(shader, freqXLoc, &freqX, SHADER_UNIFORM_FLOAT);
SetShaderValue(shader, freqYLoc, &freqY, SHADER_UNIFORM_FLOAT);
SetShaderValue(shader, ampXLoc, &ampX, SHADER_UNIFORM_FLOAT);
SetShaderValue(shader, ampYLoc, &ampY, SHADER_UNIFORM_FLOAT);
SetShaderValue(shader, speedXLoc, &speedX, SHADER_UNIFORM_FLOAT);
SetShaderValue(shader, speedYLoc, &speedY, SHADER_UNIFORM_FLOAT);

float seconds = 0.0f;

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
//----------------------------------------------------------------------------------
seconds += GetFrameTime();

SetShaderValue(shader, secondsLoc, &seconds, SHADER_UNIFORM_FLOAT);
//----------------------------------------------------------------------------------

// Draw
//----------------------------------------------------------------------------------
BeginDrawing();

ClearBackground(RAYWHITE);

BeginShaderMode(shader);

DrawTexture(texture, 0, 0, WHITE);
DrawTexture(texture, texture.width, 0, WHITE);

EndShaderMode();

EndDrawing();
//----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
UnloadShader(shader); // Unload shader
UnloadTexture(texture); // Unload texture

CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------

return 0;
}
3 changes: 1 addition & 2 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ if (RAYLIB_PHYSFS_STATIC)
endif()

# Set the header files as install files.
install(FILES
raylib-physfs.h
install(FILES raylib-physfs.h miniphysfs.h
DESTINATION include
)
Loading