diff --git a/.gitignore b/.gitignore index ef3f437a4..e1d3d9503 100644 --- a/.gitignore +++ b/.gitignore @@ -76,6 +76,9 @@ examples-switch/*/*.lst examples-switch/*/*.map examples-switch/*/*.nacp examples-switch/*/*.nro +projects/switch-nx/*.elf +projects/switch-nx/*.nacp +projects/switch-nx/*.nro # Ignore files build by xcode *.mode*v* diff --git a/examples-switch/Makefile b/examples-switch/Makefile index dce06e9b8..0d5f70a53 100644 --- a/examples-switch/Makefile +++ b/examples-switch/Makefile @@ -51,6 +51,11 @@ USE_EXTERNAL_GLFW ?= FALSE # NOTE: This variable is only used for PLATFORM_OS: LINUX USE_WAYLAND_DISPLAY ?= FALSE +# Define romfs folder location relative to Makefile +ifeq ($(PLATFORM),PLATFORM_NX) + ROMFS := romfs +endif + # Use cross-compiler for PLATFORM_RPI ifeq ($(PLATFORM),PLATFORM_RPI) USE_RPI_CROSS_COMPILER ?= FALSE @@ -561,7 +566,7 @@ else ifeq ($(PLATFORM),PLATFORM_NX) $(CXX) $@.o $(LDFLAGS) $(LDLIBS) -o $@.elf -D$(PLATFORM) $(NM) -CSn $@.elf > $@.lst nacptool --create "$(notdir $@)" "Raylib Example" "1.0.0" $@.nacp - elf2nro $@.elf $@.nro --icon=textures/resources/raylib_logo.jpg --nacp=$@.nacp + elf2nro $@.elf $@.nro --icon=textures/resources/raylib_logo.jpg --nacp=$@.nacp --romfsdir=$(CURDIR)/$(ROMFS) else $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) endif diff --git a/examples-switch/audio/audio_module_playing.c b/examples-switch/audio/audio_module_playing.c index 87dd0125d..a8c10fc6e 100644 --- a/examples-switch/audio/audio_module_playing.c +++ b/examples-switch/audio/audio_module_playing.c @@ -34,6 +34,7 @@ int main(void) const int screenWidth = 1280; const int screenHeight = 720; + // Initialize resource directory romfsInit(); SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X @@ -58,7 +59,7 @@ int main(void) circles[i].color = colors[GetRandomValue(0, 13)]; } - Music music = LoadMusicStream("resources/mini1111.xm"); + Music music = LoadMusicStream("romfs:/resources/mini1111.xm"); music.looping = false; float pitch = 1.0f; @@ -78,14 +79,14 @@ int main(void) UpdateMusicStream(music); // Update music buffer with new stream data // Restart music playing (stop and play) - if (IsKeyPressed(KEY_SPACE)) + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT)) { StopMusicStream(music); PlayMusicStream(music); } // Pause/Resume music playing - if (IsKeyPressed(KEY_P)) + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) { pause = !pause; @@ -93,8 +94,8 @@ int main(void) else ResumeMusicStream(music); } - if (IsKeyDown(KEY_DOWN)) pitch -= 0.01f; - else if (IsKeyDown(KEY_UP)) pitch += 0.01f; + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) pitch -= 0.01f; + else if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_UP)) pitch += 0.01f; SetMusicPitch(music, pitch); diff --git a/examples-switch/audio/audio_module_playing.png b/examples-switch/audio/audio_module_playing.png deleted file mode 100644 index 8bde9879d..000000000 Binary files a/examples-switch/audio/audio_module_playing.png and /dev/null differ diff --git a/examples-switch/audio/audio_multichannel_sound.c b/examples-switch/audio/audio_multichannel_sound.c index c778c1c8a..7aa7f4cca 100644 --- a/examples-switch/audio/audio_multichannel_sound.c +++ b/examples-switch/audio/audio_multichannel_sound.c @@ -14,6 +14,7 @@ ********************************************************************************************/ #include "raylib.h" +#include //------------------------------------------------------------------------------------ // Program main entry point @@ -25,12 +26,14 @@ int main(void) const int screenWidth = 1280; const int screenHeight = 720; + // Initialize resource directory + romfsInit(); InitWindow(screenWidth, screenHeight, "raylib [audio] example - Multichannel sound playing"); InitAudioDevice(); // Initialize audio device - Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file - Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file + Sound fxWav = LoadSound("romfs:/resources/sound.wav"); // Load WAV audio file + Sound fxOgg = LoadSound("romfs:/resources/target.ogg"); // Load OGG audio file SetSoundVolume(fxWav, 0.2f); @@ -42,8 +45,8 @@ int main(void) { // Update //---------------------------------------------------------------------------------- - if (IsKeyPressed(KEY_ENTER)) PlaySoundMulti(fxWav); // Play a new wav sound instance - if (IsKeyPressed(KEY_SPACE)) PlaySoundMulti(fxOgg); // Play a new ogg sound instance + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) PlaySoundMulti(fxWav); // Play a new wav sound instance + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) PlaySoundMulti(fxOgg); // Play a new ogg sound instance //---------------------------------------------------------------------------------- // Draw @@ -53,8 +56,8 @@ int main(void) ClearBackground(RAYWHITE); DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY); - DrawText("Press SPACE to play new ogg instance!", 200, 120, 20, LIGHTGRAY); - DrawText("Press ENTER to play new wav instance!", 200, 180, 20, LIGHTGRAY); + DrawText("Press A button to play new ogg instance!", 200, 120, 20, LIGHTGRAY); + DrawText("Press B button to play new wav instance!", 200, 180, 20, LIGHTGRAY); DrawText(TextFormat("CONCURRENT SOUNDS PLAYING: %02i", GetSoundsPlaying()), 220, 280, 20, RED); @@ -74,5 +77,6 @@ int main(void) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- + romfsExit(); return 0; } diff --git a/examples-switch/audio/audio_multichannel_sound.png b/examples-switch/audio/audio_multichannel_sound.png deleted file mode 100644 index 4b98b26e0..000000000 Binary files a/examples-switch/audio/audio_multichannel_sound.png and /dev/null differ diff --git a/examples-switch/audio/audio_music_stream.c b/examples-switch/audio/audio_music_stream.c index 9210b4874..97d16b791 100644 --- a/examples-switch/audio/audio_music_stream.c +++ b/examples-switch/audio/audio_music_stream.c @@ -12,6 +12,7 @@ ********************************************************************************************/ #include "raylib.h" +#include //------------------------------------------------------------------------------------ // Program main entry point @@ -23,11 +24,13 @@ int main(void) const int screenWidth = 1280; const int screenHeight = 720; + // Initialize resource directory + romfsInit(); InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)"); InitAudioDevice(); // Initialize audio device - Music music = LoadMusicStream("resources/country.mp3"); + Music music = LoadMusicStream("romfs:/resources/country.mp3"); PlayMusicStream(music); @@ -45,14 +48,14 @@ int main(void) UpdateMusicStream(music); // Update music buffer with new stream data // Restart music playing (stop and play) - if (IsKeyPressed(KEY_SPACE)) + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT)) { StopMusicStream(music); PlayMusicStream(music); } // Pause/Resume music playing - if (IsKeyPressed(KEY_P)) + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) { pause = !pause; @@ -72,14 +75,14 @@ int main(void) ClearBackground(RAYWHITE); - DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY); + DrawText("MUSIC SHOULD BE PLAYING!", screenWidth/2 - 150, screenHeight/2 - 50, 20, LIGHTGRAY); - DrawRectangle(200, 200, 400, 12, LIGHTGRAY); - DrawRectangle(200, 200, (int)(timePlayed*400.0f), 12, MAROON); - DrawRectangleLines(200, 200, 400, 12, GRAY); + DrawRectangle(screenWidth/2 - 200, screenHeight/2, 400, 12, LIGHTGRAY); + DrawRectangle(screenWidth/2 - 200, screenHeight/2, (int)(timePlayed*400.0f), 12, MAROON); + DrawRectangleLines(screenWidth/2 - 200, screenHeight/2, 400, 12, GRAY); - DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY); - DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY); + DrawText("PRESS Y button TO RESTART MUSIC", screenWidth/2 -200, screenHeight/2 + 50, 20, LIGHTGRAY); + DrawText("PRESS A button TO PAUSE/RESUME MUSIC", screenWidth/2 -200, screenHeight/2 + 80, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- @@ -94,5 +97,6 @@ int main(void) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- + romfsExit(); return 0; } diff --git a/examples-switch/audio/audio_music_stream.png b/examples-switch/audio/audio_music_stream.png deleted file mode 100644 index f8b14e159..000000000 Binary files a/examples-switch/audio/audio_music_stream.png and /dev/null differ diff --git a/examples-switch/audio/audio_raw_stream.c b/examples-switch/audio/audio_raw_stream.c index 7c07975a4..c332dcee4 100644 --- a/examples-switch/audio/audio_raw_stream.c +++ b/examples-switch/audio/audio_raw_stream.c @@ -82,6 +82,8 @@ int main(void) // Position read in to determine next frequency Vector2 mousePosition = { -100.0f, -100.0f }; + const int GAMEPAD = 0; + Vector2 thumbPosition = { screenWidth/2, screenHeight/2 }; /* // Cycles per second (hz) @@ -108,15 +110,20 @@ int main(void) // Update //---------------------------------------------------------------------------------- - // Sample mouse input. - mousePosition = GetMousePosition(); - - if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) + // Sample mouse input + if (IsGamepadAvailable(GAMEPAD)) { - float fp = (float)(mousePosition.y); + thumbPosition.x += (float) GetGamepadAxisMovement(GAMEPAD, 0) * 15; + thumbPosition.y -= (float) GetGamepadAxisMovement(GAMEPAD, 1) * 15; + } + + + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) + { + float fp = (float)(thumbPosition.y); frequency = 40.0f + (float)(fp); - float pan = (float)(mousePosition.x) / (float)screenWidth; + float pan = (float)(thumbPosition.x) / (float)screenWidth; SetAudioStreamPan(stream, pan); } @@ -185,7 +192,7 @@ int main(void) ClearBackground(RAYWHITE); DrawText(TextFormat("sine frequency: %i",(int)frequency), GetScreenWidth() - 220, 10, 20, RED); - DrawText("click mouse button to change frequency or pan", 10, 10, 20, DARKGRAY); + DrawText("Press A button to change frequency and pan with Left Thumbstick", 10, 10, 20, DARKGRAY); // Draw the current buffer state proportionate to the screen for (int i = 0; i < screenWidth; i++) @@ -195,6 +202,7 @@ int main(void) DrawPixelV(position, RED); } + DrawCircle(thumbPosition.x, thumbPosition.y, 20, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples-switch/audio/audio_raw_stream.png b/examples-switch/audio/audio_raw_stream.png deleted file mode 100644 index 344f4a710..000000000 Binary files a/examples-switch/audio/audio_raw_stream.png and /dev/null differ diff --git a/examples-switch/audio/audio_sound_loading.c b/examples-switch/audio/audio_sound_loading.c index 53c15a748..e201e6417 100644 --- a/examples-switch/audio/audio_sound_loading.c +++ b/examples-switch/audio/audio_sound_loading.c @@ -12,6 +12,7 @@ ********************************************************************************************/ #include "raylib.h" +#include //------------------------------------------------------------------------------------ // Program main entry point @@ -23,12 +24,14 @@ int main(void) const int screenWidth = 1280; const int screenHeight = 720; + // Initialize resource directory + romfsInit(); InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing"); InitAudioDevice(); // Initialize audio device - Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file - Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file + Sound fxWav = LoadSound("romfs:/resources/sound.wav"); // Load WAV audio file + Sound fxOgg = LoadSound("romfs:/resources/target.ogg"); // Load OGG audio file SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -38,8 +41,8 @@ int main(void) { // Update //---------------------------------------------------------------------------------- - if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound - if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) PlaySound(fxWav); // Play WAV sound + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) PlaySound(fxOgg); // Play OGG sound //---------------------------------------------------------------------------------- // Draw @@ -48,8 +51,8 @@ int main(void) ClearBackground(RAYWHITE); - DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY); - DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY); + DrawText("Press button A to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY); + DrawText("Press button B to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- @@ -65,5 +68,6 @@ int main(void) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- + romfsExit(); return 0; } \ No newline at end of file diff --git a/examples-switch/audio/audio_sound_loading.png b/examples-switch/audio/audio_sound_loading.png deleted file mode 100644 index 24071ce3c..000000000 Binary files a/examples-switch/audio/audio_sound_loading.png and /dev/null differ diff --git a/examples-switch/audio/audio_stream_effects.c b/examples-switch/audio/audio_stream_effects.c index 250461fc6..ebc02cbb1 100644 --- a/examples-switch/audio/audio_stream_effects.c +++ b/examples-switch/audio/audio_stream_effects.c @@ -14,6 +14,7 @@ #include "raylib.h" #include // Required for: NULL +#include // Required delay effect variables static float *delayBuffer = NULL; @@ -37,11 +38,13 @@ int main(void) const int screenWidth = 1280; const int screenHeight = 720; + // Initialize resource directory + romfsInit(); InitWindow(screenWidth, screenHeight, "raylib [audio] example - stream effects"); InitAudioDevice(); // Initialize audio device - Music music = LoadMusicStream("resources/country.mp3"); + Music music = LoadMusicStream("romfs:/resources/country.mp3"); // Allocate buffer for the delay effect delayBufferSize = 48000*2; // 1 second delay (device sampleRate*channels) @@ -66,14 +69,14 @@ int main(void) UpdateMusicStream(music); // Update music buffer with new stream data // Restart music playing (stop and play) - if (IsKeyPressed(KEY_SPACE)) + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT)) { StopMusicStream(music); PlayMusicStream(music); } // Pause/Resume music playing - if (IsKeyPressed(KEY_P)) + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) { pause = !pause; @@ -82,7 +85,7 @@ int main(void) } // Add/Remove effect: lowpass filter - if (IsKeyPressed(KEY_F)) + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_UP)) { enableEffectLPF = !enableEffectLPF; if (enableEffectLPF) AttachAudioStreamProcessor(music.stream, AudioProcessEffectLPF); @@ -90,7 +93,7 @@ int main(void) } // Add/Remove effect: delay - if (IsKeyPressed(KEY_D)) + if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) { enableEffectDelay = !enableEffectDelay; if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay); @@ -109,17 +112,17 @@ int main(void) ClearBackground(RAYWHITE); - DrawText("MUSIC SHOULD BE PLAYING!", 245, 150, 20, LIGHTGRAY); + DrawText("MUSIC SHOULD BE PLAYING!", screenWidth/2 - 200, 230, 20, LIGHTGRAY); - DrawRectangle(200, 180, 400, 12, LIGHTGRAY); - DrawRectangle(200, 180, (int)(timePlayed*400.0f), 12, MAROON); - DrawRectangleLines(200, 180, 400, 12, GRAY); + DrawRectangle(screenWidth/2 - 200, 260, 400, 12, LIGHTGRAY); + DrawRectangle(screenWidth/2 - 200, 260, (int)(timePlayed*400.0f), 12, MAROON); + DrawRectangleLines(screenWidth/2 - 200, 260, 400, 12, GRAY); - DrawText("PRESS SPACE TO RESTART MUSIC", 215, 230, 20, LIGHTGRAY); - DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 260, 20, LIGHTGRAY); + DrawText("PRESS Y button TO RESTART MUSIC", screenWidth/2 - 200, 310, 20, LIGHTGRAY); + DrawText("PRESS A button TO PAUSE/RESUME MUSIC", screenWidth/2 - 200, 340, 20, LIGHTGRAY); - DrawText(TextFormat("PRESS F TO TOGGLE LPF EFFECT: %s", enableEffectLPF? "ON" : "OFF"), 200, 320, 20, GRAY); - DrawText(TextFormat("PRESS D TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), 180, 350, 20, GRAY); + DrawText(TextFormat("PRESS X button TO TOGGLE LPF EFFECT: %s", enableEffectLPF? "ON" : "OFF"), screenWidth/2 - 200, 400, 20, GRAY); + DrawText(TextFormat("PRESS B button TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), screenWidth/2 - 200, 430, 20, GRAY); EndDrawing(); //---------------------------------------------------------------------------------- @@ -136,6 +139,7 @@ int main(void) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- + romfsExit(); return 0; } diff --git a/examples-switch/audio/audio_stream_effects.png b/examples-switch/audio/audio_stream_effects.png deleted file mode 100644 index 4aaee8b3e..000000000 Binary files a/examples-switch/audio/audio_stream_effects.png and /dev/null differ diff --git a/examples-switch/audio/resources/LICENSE.md b/examples-switch/romfs/resources/LICENSE.md similarity index 100% rename from examples-switch/audio/resources/LICENSE.md rename to examples-switch/romfs/resources/LICENSE.md diff --git a/examples-switch/audio/resources/coin.wav b/examples-switch/romfs/resources/coin.wav similarity index 100% rename from examples-switch/audio/resources/coin.wav rename to examples-switch/romfs/resources/coin.wav diff --git a/examples-switch/audio/resources/country.mp3 b/examples-switch/romfs/resources/country.mp3 similarity index 100% rename from examples-switch/audio/resources/country.mp3 rename to examples-switch/romfs/resources/country.mp3 diff --git a/examples-switch/audio/resources/mini1111.xm b/examples-switch/romfs/resources/mini1111.xm similarity index 100% rename from examples-switch/audio/resources/mini1111.xm rename to examples-switch/romfs/resources/mini1111.xm diff --git a/examples-switch/audio/resources/sound.wav b/examples-switch/romfs/resources/sound.wav similarity index 100% rename from examples-switch/audio/resources/sound.wav rename to examples-switch/romfs/resources/sound.wav diff --git a/examples-switch/audio/resources/spring.wav b/examples-switch/romfs/resources/spring.wav similarity index 100% rename from examples-switch/audio/resources/spring.wav rename to examples-switch/romfs/resources/spring.wav diff --git a/examples-switch/audio/resources/target.flac b/examples-switch/romfs/resources/target.flac similarity index 100% rename from examples-switch/audio/resources/target.flac rename to examples-switch/romfs/resources/target.flac diff --git a/examples-switch/audio/resources/target.ogg b/examples-switch/romfs/resources/target.ogg similarity index 100% rename from examples-switch/audio/resources/target.ogg rename to examples-switch/romfs/resources/target.ogg diff --git a/examples-switch/audio/resources/weird.wav b/examples-switch/romfs/resources/weird.wav similarity index 100% rename from examples-switch/audio/resources/weird.wav rename to examples-switch/romfs/resources/weird.wav diff --git a/examples-switch/textures/textures_image_drawing.c b/examples-switch/textures/textures_image_drawing.c index f7e7a86fc..688bb7ace 100644 --- a/examples-switch/textures/textures_image_drawing.c +++ b/examples-switch/textures/textures_image_drawing.c @@ -14,6 +14,7 @@ ********************************************************************************************/ #include "raylib.h" +#include //------------------------------------------------------------------------------------ // Program main entry point @@ -25,16 +26,18 @@ int main(void) const int screenWidth = 1280; const int screenHeight = 720; + // Initialize resource directory + romfsInit(); InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - Image cat = LoadImage("resources/cat.png"); // Load image in CPU memory (RAM) + Image cat = LoadImage("romfs:/resources/cat.png"); // Load image in CPU memory (RAM) ImageCrop(&cat, (Rectangle){ 100, 10, 280, 380 }); // Crop an image piece ImageFlipHorizontal(&cat); // Flip cropped image horizontally ImageResize(&cat, 150, 200); // Resize flipped-cropped image - Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) + Image parrots = LoadImage("romfs:/resources/parrots.png"); // Load image in CPU memory (RAM) // Draw one image over the other with a scaling of 1.5f ImageDraw(&parrots, cat, (Rectangle){ 0, 0, (float)cat.width, (float)cat.height }, (Rectangle){ 30, 40, cat.width*1.5f, cat.height*1.5f }, WHITE); @@ -91,6 +94,6 @@ int main(void) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- - + romfsExit(); return 0; } \ No newline at end of file