switch-examples: Updated Makefile for romfs and updated all audio examples for switch
This commit is contained in:
parent
394c5e178f
commit
6719c57ba8
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -76,6 +76,9 @@ examples-switch/*/*.lst
|
||||||
examples-switch/*/*.map
|
examples-switch/*/*.map
|
||||||
examples-switch/*/*.nacp
|
examples-switch/*/*.nacp
|
||||||
examples-switch/*/*.nro
|
examples-switch/*/*.nro
|
||||||
|
projects/switch-nx/*.elf
|
||||||
|
projects/switch-nx/*.nacp
|
||||||
|
projects/switch-nx/*.nro
|
||||||
|
|
||||||
# Ignore files build by xcode
|
# Ignore files build by xcode
|
||||||
*.mode*v*
|
*.mode*v*
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,11 @@ USE_EXTERNAL_GLFW ?= FALSE
|
||||||
# NOTE: This variable is only used for PLATFORM_OS: LINUX
|
# NOTE: This variable is only used for PLATFORM_OS: LINUX
|
||||||
USE_WAYLAND_DISPLAY ?= FALSE
|
USE_WAYLAND_DISPLAY ?= FALSE
|
||||||
|
|
||||||
|
# Define romfs folder location relative to Makefile
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_NX)
|
||||||
|
ROMFS := romfs
|
||||||
|
endif
|
||||||
|
|
||||||
# Use cross-compiler for PLATFORM_RPI
|
# Use cross-compiler for PLATFORM_RPI
|
||||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
USE_RPI_CROSS_COMPILER ?= FALSE
|
USE_RPI_CROSS_COMPILER ?= FALSE
|
||||||
|
|
@ -561,7 +566,7 @@ else ifeq ($(PLATFORM),PLATFORM_NX)
|
||||||
$(CXX) $@.o $(LDFLAGS) $(LDLIBS) -o $@.elf -D$(PLATFORM)
|
$(CXX) $@.o $(LDFLAGS) $(LDLIBS) -o $@.elf -D$(PLATFORM)
|
||||||
$(NM) -CSn $@.elf > $@.lst
|
$(NM) -CSn $@.elf > $@.lst
|
||||||
nacptool --create "$(notdir $@)" "Raylib Example" "1.0.0" $@.nacp
|
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
|
else
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ int main(void)
|
||||||
const int screenWidth = 1280;
|
const int screenWidth = 1280;
|
||||||
const int screenHeight = 720;
|
const int screenHeight = 720;
|
||||||
|
|
||||||
|
// Initialize resource directory
|
||||||
romfsInit();
|
romfsInit();
|
||||||
|
|
||||||
SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X
|
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)];
|
circles[i].color = colors[GetRandomValue(0, 13)];
|
||||||
}
|
}
|
||||||
|
|
||||||
Music music = LoadMusicStream("resources/mini1111.xm");
|
Music music = LoadMusicStream("romfs:/resources/mini1111.xm");
|
||||||
music.looping = false;
|
music.looping = false;
|
||||||
float pitch = 1.0f;
|
float pitch = 1.0f;
|
||||||
|
|
||||||
|
|
@ -78,14 +79,14 @@ int main(void)
|
||||||
UpdateMusicStream(music); // Update music buffer with new stream data
|
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||||
|
|
||||||
// Restart music playing (stop and play)
|
// Restart music playing (stop and play)
|
||||||
if (IsKeyPressed(KEY_SPACE))
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
|
||||||
{
|
{
|
||||||
StopMusicStream(music);
|
StopMusicStream(music);
|
||||||
PlayMusicStream(music);
|
PlayMusicStream(music);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause/Resume music playing
|
// Pause/Resume music playing
|
||||||
if (IsKeyPressed(KEY_P))
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
|
||||||
{
|
{
|
||||||
pause = !pause;
|
pause = !pause;
|
||||||
|
|
||||||
|
|
@ -93,8 +94,8 @@ int main(void)
|
||||||
else ResumeMusicStream(music);
|
else ResumeMusicStream(music);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsKeyDown(KEY_DOWN)) pitch -= 0.01f;
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) pitch -= 0.01f;
|
||||||
else if (IsKeyDown(KEY_UP)) pitch += 0.01f;
|
else if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_UP)) pitch += 0.01f;
|
||||||
|
|
||||||
SetMusicPitch(music, pitch);
|
SetMusicPitch(music, pitch);
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 47 KiB |
|
|
@ -14,6 +14,7 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
#include <switch.h>
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
|
|
@ -25,12 +26,14 @@ int main(void)
|
||||||
const int screenWidth = 1280;
|
const int screenWidth = 1280;
|
||||||
const int screenHeight = 720;
|
const int screenHeight = 720;
|
||||||
|
|
||||||
|
// Initialize resource directory
|
||||||
|
romfsInit();
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - Multichannel sound playing");
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - Multichannel sound playing");
|
||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
|
Sound fxWav = LoadSound("romfs:/resources/sound.wav"); // Load WAV audio file
|
||||||
Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file
|
Sound fxOgg = LoadSound("romfs:/resources/target.ogg"); // Load OGG audio file
|
||||||
|
|
||||||
SetSoundVolume(fxWav, 0.2f);
|
SetSoundVolume(fxWav, 0.2f);
|
||||||
|
|
||||||
|
|
@ -42,8 +45,8 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsKeyPressed(KEY_ENTER)) PlaySoundMulti(fxWav); // Play a new wav sound instance
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) 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_DOWN)) PlaySoundMulti(fxOgg); // Play a new ogg sound instance
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -53,8 +56,8 @@ int main(void)
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY);
|
DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, GRAY);
|
||||||
DrawText("Press SPACE to play new ogg instance!", 200, 120, 20, LIGHTGRAY);
|
DrawText("Press A button to play new ogg instance!", 200, 120, 20, LIGHTGRAY);
|
||||||
DrawText("Press ENTER to play new wav instance!", 200, 180, 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);
|
DrawText(TextFormat("CONCURRENT SOUNDS PLAYING: %02i", GetSoundsPlaying()), 220, 280, 20, RED);
|
||||||
|
|
||||||
|
|
@ -74,5 +77,6 @@ int main(void)
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
romfsExit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 16 KiB |
|
|
@ -12,6 +12,7 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
#include <switch.h>
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
|
|
@ -23,11 +24,13 @@ int main(void)
|
||||||
const int screenWidth = 1280;
|
const int screenWidth = 1280;
|
||||||
const int screenHeight = 720;
|
const int screenHeight = 720;
|
||||||
|
|
||||||
|
// Initialize resource directory
|
||||||
|
romfsInit();
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)");
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)");
|
||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
Music music = LoadMusicStream("resources/country.mp3");
|
Music music = LoadMusicStream("romfs:/resources/country.mp3");
|
||||||
|
|
||||||
PlayMusicStream(music);
|
PlayMusicStream(music);
|
||||||
|
|
||||||
|
|
@ -45,14 +48,14 @@ int main(void)
|
||||||
UpdateMusicStream(music); // Update music buffer with new stream data
|
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||||
|
|
||||||
// Restart music playing (stop and play)
|
// Restart music playing (stop and play)
|
||||||
if (IsKeyPressed(KEY_SPACE))
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
|
||||||
{
|
{
|
||||||
StopMusicStream(music);
|
StopMusicStream(music);
|
||||||
PlayMusicStream(music);
|
PlayMusicStream(music);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause/Resume music playing
|
// Pause/Resume music playing
|
||||||
if (IsKeyPressed(KEY_P))
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
|
||||||
{
|
{
|
||||||
pause = !pause;
|
pause = !pause;
|
||||||
|
|
||||||
|
|
@ -72,14 +75,14 @@ int main(void)
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
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(screenWidth/2 - 200, screenHeight/2, 400, 12, LIGHTGRAY);
|
||||||
DrawRectangle(200, 200, (int)(timePlayed*400.0f), 12, MAROON);
|
DrawRectangle(screenWidth/2 - 200, screenHeight/2, (int)(timePlayed*400.0f), 12, MAROON);
|
||||||
DrawRectangleLines(200, 200, 400, 12, GRAY);
|
DrawRectangleLines(screenWidth/2 - 200, screenHeight/2, 400, 12, GRAY);
|
||||||
|
|
||||||
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY);
|
DrawText("PRESS Y button TO RESTART MUSIC", screenWidth/2 -200, screenHeight/2 + 50, 20, LIGHTGRAY);
|
||||||
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY);
|
DrawText("PRESS A button TO PAUSE/RESUME MUSIC", screenWidth/2 -200, screenHeight/2 + 80, 20, LIGHTGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -94,5 +97,6 @@ int main(void)
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
romfsExit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB |
|
|
@ -82,6 +82,8 @@ int main(void)
|
||||||
|
|
||||||
// Position read in to determine next frequency
|
// Position read in to determine next frequency
|
||||||
Vector2 mousePosition = { -100.0f, -100.0f };
|
Vector2 mousePosition = { -100.0f, -100.0f };
|
||||||
|
const int GAMEPAD = 0;
|
||||||
|
Vector2 thumbPosition = { screenWidth/2, screenHeight/2 };
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Cycles per second (hz)
|
// Cycles per second (hz)
|
||||||
|
|
@ -108,15 +110,20 @@ int main(void)
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Sample mouse input.
|
// Sample mouse input
|
||||||
mousePosition = GetMousePosition();
|
if (IsGamepadAvailable(GAMEPAD))
|
||||||
|
|
||||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
|
|
||||||
{
|
{
|
||||||
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);
|
frequency = 40.0f + (float)(fp);
|
||||||
|
|
||||||
float pan = (float)(mousePosition.x) / (float)screenWidth;
|
float pan = (float)(thumbPosition.x) / (float)screenWidth;
|
||||||
SetAudioStreamPan(stream, pan);
|
SetAudioStreamPan(stream, pan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,7 +192,7 @@ int main(void)
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawText(TextFormat("sine frequency: %i",(int)frequency), GetScreenWidth() - 220, 10, 20, RED);
|
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
|
// Draw the current buffer state proportionate to the screen
|
||||||
for (int i = 0; i < screenWidth; i++)
|
for (int i = 0; i < screenWidth; i++)
|
||||||
|
|
@ -195,6 +202,7 @@ int main(void)
|
||||||
|
|
||||||
DrawPixelV(position, RED);
|
DrawPixelV(position, RED);
|
||||||
}
|
}
|
||||||
|
DrawCircle(thumbPosition.x, thumbPosition.y, 20, DARKGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 16 KiB |
|
|
@ -12,6 +12,7 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
#include <switch.h>
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
|
|
@ -23,12 +24,14 @@ int main(void)
|
||||||
const int screenWidth = 1280;
|
const int screenWidth = 1280;
|
||||||
const int screenHeight = 720;
|
const int screenHeight = 720;
|
||||||
|
|
||||||
|
// Initialize resource directory
|
||||||
|
romfsInit();
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
|
||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
|
Sound fxWav = LoadSound("romfs:/resources/sound.wav"); // Load WAV audio file
|
||||||
Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG 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
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -38,8 +41,8 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT)) PlaySound(fxWav); // Play WAV sound
|
||||||
if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) PlaySound(fxOgg); // Play OGG sound
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -48,8 +51,8 @@ int main(void)
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
|
DrawText("Press button A to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
|
||||||
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
|
DrawText("Press button B to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -65,5 +68,6 @@ int main(void)
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
romfsExit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB |
|
|
@ -14,6 +14,7 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include <stdlib.h> // Required for: NULL
|
#include <stdlib.h> // Required for: NULL
|
||||||
|
#include <switch.h>
|
||||||
|
|
||||||
// Required delay effect variables
|
// Required delay effect variables
|
||||||
static float *delayBuffer = NULL;
|
static float *delayBuffer = NULL;
|
||||||
|
|
@ -37,11 +38,13 @@ int main(void)
|
||||||
const int screenWidth = 1280;
|
const int screenWidth = 1280;
|
||||||
const int screenHeight = 720;
|
const int screenHeight = 720;
|
||||||
|
|
||||||
|
// Initialize resource directory
|
||||||
|
romfsInit();
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - stream effects");
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - stream effects");
|
||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
Music music = LoadMusicStream("resources/country.mp3");
|
Music music = LoadMusicStream("romfs:/resources/country.mp3");
|
||||||
|
|
||||||
// Allocate buffer for the delay effect
|
// Allocate buffer for the delay effect
|
||||||
delayBufferSize = 48000*2; // 1 second delay (device sampleRate*channels)
|
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
|
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||||
|
|
||||||
// Restart music playing (stop and play)
|
// Restart music playing (stop and play)
|
||||||
if (IsKeyPressed(KEY_SPACE))
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
|
||||||
{
|
{
|
||||||
StopMusicStream(music);
|
StopMusicStream(music);
|
||||||
PlayMusicStream(music);
|
PlayMusicStream(music);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause/Resume music playing
|
// Pause/Resume music playing
|
||||||
if (IsKeyPressed(KEY_P))
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
|
||||||
{
|
{
|
||||||
pause = !pause;
|
pause = !pause;
|
||||||
|
|
||||||
|
|
@ -82,7 +85,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add/Remove effect: lowpass filter
|
// Add/Remove effect: lowpass filter
|
||||||
if (IsKeyPressed(KEY_F))
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_UP))
|
||||||
{
|
{
|
||||||
enableEffectLPF = !enableEffectLPF;
|
enableEffectLPF = !enableEffectLPF;
|
||||||
if (enableEffectLPF) AttachAudioStreamProcessor(music.stream, AudioProcessEffectLPF);
|
if (enableEffectLPF) AttachAudioStreamProcessor(music.stream, AudioProcessEffectLPF);
|
||||||
|
|
@ -90,7 +93,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add/Remove effect: delay
|
// Add/Remove effect: delay
|
||||||
if (IsKeyPressed(KEY_D))
|
if (IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN))
|
||||||
{
|
{
|
||||||
enableEffectDelay = !enableEffectDelay;
|
enableEffectDelay = !enableEffectDelay;
|
||||||
if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
if (enableEffectDelay) AttachAudioStreamProcessor(music.stream, AudioProcessEffectDelay);
|
||||||
|
|
@ -109,17 +112,17 @@ int main(void)
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
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(screenWidth/2 - 200, 260, 400, 12, LIGHTGRAY);
|
||||||
DrawRectangle(200, 180, (int)(timePlayed*400.0f), 12, MAROON);
|
DrawRectangle(screenWidth/2 - 200, 260, (int)(timePlayed*400.0f), 12, MAROON);
|
||||||
DrawRectangleLines(200, 180, 400, 12, GRAY);
|
DrawRectangleLines(screenWidth/2 - 200, 260, 400, 12, GRAY);
|
||||||
|
|
||||||
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 230, 20, LIGHTGRAY);
|
DrawText("PRESS Y button TO RESTART MUSIC", screenWidth/2 - 200, 310, 20, LIGHTGRAY);
|
||||||
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 260, 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 X button TO TOGGLE LPF EFFECT: %s", enableEffectLPF? "ON" : "OFF"), screenWidth/2 - 200, 400, 20, GRAY);
|
||||||
DrawText(TextFormat("PRESS D TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), 180, 350, 20, GRAY);
|
DrawText(TextFormat("PRESS B button TO TOGGLE DELAY EFFECT: %s", enableEffectDelay? "ON" : "OFF"), screenWidth/2 - 200, 430, 20, GRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -136,6 +139,7 @@ int main(void)
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
romfsExit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 16 KiB |
|
|
@ -14,6 +14,7 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
#include <switch.h>
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
|
|
@ -25,16 +26,18 @@ int main(void)
|
||||||
const int screenWidth = 1280;
|
const int screenWidth = 1280;
|
||||||
const int screenHeight = 720;
|
const int screenHeight = 720;
|
||||||
|
|
||||||
|
// Initialize resource directory
|
||||||
|
romfsInit();
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing");
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing");
|
||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// 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
|
ImageCrop(&cat, (Rectangle){ 100, 10, 280, 380 }); // Crop an image piece
|
||||||
ImageFlipHorizontal(&cat); // Flip cropped image horizontally
|
ImageFlipHorizontal(&cat); // Flip cropped image horizontally
|
||||||
ImageResize(&cat, 150, 200); // Resize flipped-cropped image
|
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
|
// 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);
|
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
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
romfsExit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user