Skip to content

Commit

Permalink
some bugs have been fixed.
Browse files Browse the repository at this point in the history
some bugs have been fixed.

added a shortcut function for loading resources.

fixed all the examples
  • Loading branch information
GuvaCode committed Dec 20, 2023
1 parent 0358ce9 commit b780b72
Show file tree
Hide file tree
Showing 55 changed files with 179 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ procedure ProcessAudio(buffer: pointer; frames:LongWord); cdecl;

AttachAudioMixedProcessor(@ProcessAudio);

music := LoadMusicStream('resources/country.mp3');
sound := LoadSound('resources/coin.wav');
music := LoadMusicStream(PChar(GetApplicationDirectory + 'resources/country.mp3'));
sound := LoadSound(PChar(GetApplicationDirectory + 'resources/coin.wav'));

PlayMusicStream(music);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ CircleWave = record
circles[i].color := colors[GetRandomValue(0, 13)];
end;

music := LoadMusicStream('resources/mini1111.xm');
music := LoadMusicStream(PChar(GetApplicationDirectory + 'resources/mini1111.xm'));
music.looping := false;

pitch := 1.0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{*******************************************************************************************
*
* raylib [audio] example - Multichannel sound playing
* raylib [audio] example - Playing sound multiple times
*
* This example has been created using raylib 2.6 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example originally created with raylib 4.6
*
* Example contributed by Chris Camacho (@chriscamacho) and reviewed by Ramon Santamaria (@raysan5)
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2023 Jeffery Myers (@JeffM2501)
*
* Copyright (c) 2019 Chris Camacho (@chriscamacho) and Ramon Santamaria (@raysan5)
* Pascal conversion (c) 2021 Gunko Vadim (@guvacode)
********************************************************************************************}

Expand All @@ -20,48 +21,55 @@
const
screenWidth = 800;
screenHeight = 450;
MAX_SOUNDS = 10;

var
fxWav,fxOgg: TSound;

soundArray: array[0..MAX_SOUNDS] of TSound;
currentSound, i: Integer;
dir: string;
begin

InitWindow(screenWidth, screenHeight, 'raylib [audio] example - Multichannel sound playing');
InitWindow(screenWidth, screenHeight, 'raylib [audio] example - playing sound multiple times');

InitAudioDevice(); // Initialize audio device

fxWav := LoadSound('resources/sound.wav'); // Load WAV audio file
fxOgg := LoadSound('resources/target.ogg'); // Load OGG audio file
// load the sound list
soundArray[0] := LoadSound(PChar(GetApplicationDirectory + 'resources/sound.wav')); // Load WAV audio file into the first slot as the 'source' sound
// this sound owns the sample data
for i := 1 to MAX_SOUNDS do
soundArray[i] := LoadSoundAlias(soundArray[0]); // Load an alias of the sound into slots 1-9. These do not own the sound data, but can be played
currentSound := 0; // set the sound list to the start

SetSoundVolume(fxWav, 0.2);

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
SetTargetFPS(60); // Set our game to run at 60 frames-per-second

// Main game loop
while not WindowShouldClose() do // Detect window close button or ESC key
begin
// Update
if IsKeyPressed(KEY_ENTER) then PlaySoundMulti(fxWav); // Play a new wav sound instance
if IsKeyPressed(KEY_SPACE) then PlaySoundMulti(fxOgg); // Play a new ogg sound instance

if IsKeyPressed(KEY_SPACE) then
begin
PlaySound(soundArray[currentSound]); // play the next open sound slot
Inc(currentSound); // increment the sound slot
if (currentSound >= MAX_SOUNDS) then // if the sound slot is out of bounds, go back to 0
currentSound := 0;
end;


// Draw
BeginDrawing();

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(TextFormat('CONCURRENT SOUNDS PLAYING: %02i', GetSoundsPlaying), 220, 280, 20, RED);
DrawText('Press SPACE to PLAY a WAV sound!', 200, 180, 20, LIGHTGRAY);

EndDrawing();
end;
// De-Initialization
StopSoundMulti(); // We must stop the buffer pool before unloading
UnloadSound(fxWav); // Unload sound data
UnloadSound(fxOgg); // Unload sound data
for i := 1 to MAX_SOUNDS do
UnloadSoundAlias(soundArray[i]); // Unload sound aliases
UnloadSound(soundArray[0]); // Unload source sound data
CloseAudioDevice(); // Close audio device
CloseWindow(); // Close window and OpenGL context

CloseWindow(); // Close window and OpenGL contex
end.

2 changes: 1 addition & 1 deletion examples/audio/audio_music_stream/audio_music_stream.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

InitAudioDevice(); // Initialize audio device

music := LoadMusicStream('resources/country.mp3');
music := LoadMusicStream(PChar(GetApplicationDirectory + 'resources/country.mp3'));

PlayMusicStream(music);

Expand Down
2 changes: 1 addition & 1 deletion examples/audio/audio_raw_stream/audio_raw_stream.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="../../../binary/audio_raw_stream"/>
<Filename Value="../../../binary/audio_raw_streams"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
Expand Down
2 changes: 1 addition & 1 deletion examples/audio/audio_raw_stream/audio_raw_stream.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
********************************************************************************************)
unit audio_raw_stream;

{$IFDEF FPC}{$MODE DELPHIUNICODE}{$ENDIF}


interface

Expand Down
4 changes: 2 additions & 2 deletions examples/audio/audio_sound_loading/audio_sound_loadig.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
InitWindow(screenWidth, screenHeight, 'raylib [audio] example - sound loading and playing');
InitAudioDevice(); // Initialize audio device

fxWav := LoadSound('resources/sound.wav'); // Load WAV audio file
fxOgg := LoadSound('resources/target.ogg'); // Load OGG audio file
fxWav := LoadSound(GetAppDir('resources/sound.wav')); // Load WAV audio file
fxOgg := LoadSound(GetAppDir('resources/target.ogg')); // Load OGG audio file

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/core/core_3d_picking/core_3d_picking.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
begin
// Update
//----------------------------------------------------------------------------------
UpdateCamera(@Camera,CAMERA_FREE);
UpdateCamera(@Camera,CAMERA_FIRST_PERSON);

if IsMouseButtonPressed(MOUSE_BUTTON_LEFT) then
begin
Expand Down
16 changes: 5 additions & 11 deletions examples/core/core_split_screen/core_split_screen.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
screenHeight = 450;

var
textureGrid : TTexture2D;

cameraPlayer1 :TCamera;
cameraPlayer2 :TCamera;
img: TImage;

screenPlayer1: TRenderTexture;
screenPlayer2: TRenderTexture;
splitScreenRect: TRectangle;
Expand All @@ -50,8 +50,8 @@
begin
for z :=-count to count do
begin
DrawCubeTexture(textureGrid,Vector3Create(x*spacing, 1.5, z*spacing), 1, 1, 1, GREEN);
DrawCubeTexture(textureGrid,Vector3Create(x*spacing, 0.5, z*spacing), 0.25, 1, 0.25, BROWN);
DrawCube(Vector3Create(x*spacing, 1.5, z*spacing), 1, 1, 1, GREEN);
DrawCube(Vector3Create(x*spacing, 0.5, z*spacing), 0.25, 1, 0.25, BROWN);
end;
end;

Expand All @@ -66,12 +66,6 @@
//--------------------------------------------------------------------------------------
InitWindow(screenWidth, screenHeight, 'raylib [core] example - split screen');

// Generate a simple texture to use for trees
img := GenImageChecked(256, 256, 32, 32, DARKGRAY, WHITE);
textureGrid := LoadTextureFromImage(img);
UnloadImage(img);
SetTextureFilter(textureGrid, TEXTURE_FILTER_ANISOTROPIC_16X);
SetTextureWrap(textureGrid, TEXTURE_WRAP_CLAMP);

// Setup player 1 camera and screen
cameraPlayer1.fovy := 45.0;
Expand Down Expand Up @@ -164,7 +158,7 @@
//--------------------------------------------------------------------------------------
UnloadRenderTexture(screenPlayer1); // Unload render texture
UnloadRenderTexture(screenPlayer2); // Unload render texture
UnloadTexture(textureGrid); // Unload texture

CloseWindow(); // Close window and OpenGL context

//--------------------------------------------------------------------------------------
Expand Down
Binary file added examples/core/core_storage_values/storage.data
Binary file not shown.
6 changes: 3 additions & 3 deletions examples/core/core_vr_simulator/core_vr_simulator.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
config := LoadVrStereoConfig(device);

// Distortion shader (uses device lens distortion and chroma)
distortion := LoadShader(nil, TextFormat('resources/distortion%i.fs', GLSL_VERSION));
distortion := LoadShader(nil, TextFormat(GetAppDir('resources/distortion%i.fs'), GLSL_VERSION));
// Update distortion shader with lens and distortion-scale parameters
SetShaderValue(distortion, GetShaderLocation(distortion, 'leftLensCenter'),
@config.leftLensCenter, SHADER_UNIFORM_VEC2);
Expand Down Expand Up @@ -107,7 +107,7 @@
camera.projection := CAMERA_PERSPECTIVE; // Camera type

cubePosition := Vector3Create( 0.0, 0.0, 0.0 );
SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set first person camera mode


SetTargetFPS(90); // Set our game to run at 90 frames-per-second
//--------------------------------------------------------------------------------------
Expand All @@ -116,7 +116,7 @@
begin
// Update
//----------------------------------------------------------------------------------
UpdateCamera(@camera);
UpdateCamera(@camera,CAMERA_FIRST_PERSON);
//----------------------------------------------------------------------------------

// Draw
Expand Down
4 changes: 2 additions & 2 deletions examples/core/core_world_screen/core_world_screen.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
cubePosition := Vector3Create( 0.0, 0.0, 0.0 );
cubeScreenPosition := Vector2Create( 0.0, 0.0 );

SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode


SetTargetFPS(60);// Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
Expand All @@ -50,7 +50,7 @@
begin
// Update
//----------------------------------------------------------------------------------
UpdateCamera(@camera);
UpdateCamera(@camera, CAMERA_FREE);

// Calculate cube screen space position (with a little offset to be in top)
cubeScreenPosition := GetWorldToScreen(Vector3Create(cubePosition.x, cubePosition.y + 2.5, cubePosition.z), camera);
Expand Down
6 changes: 3 additions & 3 deletions examples/models/models_animation/models_animation.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
Camera.Fovy := 45.0; // Camera field-of-view Y
Camera.Projection := CAMERA_PERSPECTIVE; // Camera mode type

Model := LoadModel('resources/models/iqm/guy.iqm'); // Load the animated model mesh and basic data
Texture := LoadTexture('resources/models/iqm/guytex.png'); // Load model texture and set material
Model := LoadModel(GetAppDir('resources/models/iqm/guy.iqm')); // Load the animated model mesh and basic data
Texture := LoadTexture(GetAppDir('resources/models/iqm/guytex.png')); // Load model texture and set material
SetMaterialTexture(@Model.Materials[0], MATERIAL_MAP_DIFFUSE, Texture); // Set model material map texture

Position := Vector3Create(0.0, 0.0, 0.0); // Set model position

// Load animation data
AnimsCount := 0;
Anims := LoadModelAnimations('resources/models/iqm/guyanim.iqm', @AnimsCount);
Anims := LoadModelAnimations(GetAppDir('resources/models/iqm/guyanim.iqm'), @AnimsCount);
AnimFrameCounter := 0;
DisableCursor;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
Expand Down
2 changes: 1 addition & 1 deletion examples/models/models_billboard/models_billboard.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
Vector3Create(0.0,1.0,0.0), //up
45.0, CAMERA_PERSPECTIVE);

bill := LoadTexture('resources/billboard.png'); // Our billboard texture
bill := LoadTexture(GetAppDir('resources/billboard.png')); // Our billboard texture
billPositionStatic := Vector3Create(0, 2, 0); // Position of billboard
billPositionRotating := Vector3Create(1, 2, 1);

Expand Down
4 changes: 2 additions & 2 deletions examples/models/models_cubicmap/models_cubicmap.pas
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
Vector3Create(0.0,0.0,0.0),
Vector3Create(0.0,1.0,0.0),45.0,0);

image := LoadImage('resources/cubicmap.png'); // Load cubicmap image (RAM)
image := LoadImage(GetAppDir('resources/cubicmap.png')); // Load cubicmap image (RAM)

cubicmap := LoadTextureFromImage(image); // Convert image to texture to display (VRAM)

mesh := GenMeshCubicmap(image, Vector3Create(1.0,1.0,1.0));
model := LoadModelFromMesh(mesh);

// NOTE: By default each cube is mapped to one part of texture atlas
texture := LoadTexture('resources/cubicmap_atlas.png'); // Load map texture
texture := LoadTexture(GetAppDir('resources/cubicmap_atlas.png')); // Load map texture
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture := texture; // Set map diffuse texture

Vector3Set(@mapPosition,-16.0, 0.0, -8.0); // Set model position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ procedure DrawCubeTextureRec(texture: TTexture2D; source: TRectangle; position:
camera.projection := CAMERA_PERSPECTIVE;

// Load texture to be applied to the cubes sides
texture := LoadTexture('resources/cubicmap_atlas.png');
texture := LoadTexture(GetAppDir('resources/cubicmap_atlas.png'));
SetTargetFPS(60);// Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
Vector3Create(0.0,1.0,0.0),45.0,0);


imMap := LoadImage('resources/cubicmap.png'); // Load cubicmap image (RAM)
imMap := LoadImage(GetAppDir('resources/cubicmap.png')); // Load cubicmap image (RAM)
cubicmap := LoadTextureFromImage(imMap); // Convert image to texture to display (VRAM)
mesh := GenMeshCubicmap(imMap,Vector3Create(1.0,1.0,1.0));
model := LoadModelFromMesh(mesh);

// NOTE: By default each cube is mapped to one part of texture atlas
texture := LoadTexture('resources/cubicmap_atlas.png'); // Load map texture
texture := LoadTexture(GetAppDir('resources/cubicmap_atlas.png')); // Load map texture
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture := texture; // Set map diffuse texture

// Get map image data to be used for collision detection
Expand Down
2 changes: 1 addition & 1 deletion examples/models/models_heightmap/models_heightmap.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Vector3Create(0.0,0.0,0.0),
Vector3Create(0.0,1.0,0.0),45.0,0);

image := LoadImage('resources/heightmap.png'); // Load heightmap image (RAM)
image := LoadImage(GetAppDir('resources/heightmap.png')); // Load heightmap image (RAM)
texture := LoadTextureFromImage(image); // Convert image to texture (VRAM)
mesh := GenMeshHeightmap(image, Vector3Create(16,8,16)); // Generate heightmap mesh (RAM and VRAM)
model := LoadModelFromMesh(mesh); // Load model from generated mesh
Expand Down
4 changes: 2 additions & 2 deletions examples/models/models_loading/models_loading.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
Camera.Fovy := 45.0; // Camera field-of-view Y
Camera.Projection := CAMERA_PERSPECTIVE; // Camera mode type

Model := LoadModel('resources/models/obj/castle.obj'); // Load model
Texture := LoadTexture('resources/models/obj/castle_diffuse.png'); // Load model texture
Model := LoadModel(GetAppDir('resources/models/obj/castle.obj')); // Load model
Texture := LoadTexture(GetAppDir('resources/models/obj/castle_diffuse.png')); // Load model texture
Model.Materials[0].Maps[MATERIAL_MAP_DIFFUSE].Texture := Texture; // Set map diffuse texture

Position := Vector3Create(0.0, 0.0, 0.0); // Set model position
Expand Down
12 changes: 6 additions & 6 deletions examples/models/models_loading_gltf/models_loading_gltf.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
camera.projection := CAMERA_PERSPECTIVE; // Camera mode type

// Load gltf model
model := LoadModel('resources/models/gltf/robot.glb');
model := LoadModel(GetAppDir('resources/models/gltf/robot.glb'));

// Load gltf model animations
animsCount := 0;
animIndex := 0;
animCurrentFrame := 0;
modelAnimations := LoadModelAnimations('resources/models/gltf/robot.glb', @animsCount);
modelAnimations := LoadModelAnimations(GetAppDir('resources/models/gltf/robot.glb'), @animsCount);

position := Vector3Create( 0.0, 0.0, 0.0 ); // Set model position

Expand All @@ -71,17 +71,17 @@
// Update
//----------------------------------------------------------------------------------
// Select current animation
if (IsKeyPressed(KEY_UP)) then animIndex := (animIndex + 1) mod animsCount
if (IsKeyPressed(KEY_z)) then animIndex := (animIndex + 1) mod animsCount
else
if (IsKeyPressed(KEY_DOWN)) then animIndex := (animIndex + animsCount - 1) mod animsCount;
if (IsKeyPressed(KEY_x)) then animIndex := (animIndex + animsCount - 1) mod animsCount;

// Update model animation
anim := modelAnimations[animIndex];
animCurrentFrame := (animCurrentFrame + 1) mod anim.frameCount;
UpdateModelAnimation(model, anim, animCurrentFrame);

// Update camera
UpdateCamera(@camera,CAMERA_FREE);
UpdateCamera(@camera,CAMERA_THIRD_PERSON);

//----------------------------------------------------------------------------------

Expand All @@ -95,7 +95,7 @@
DrawGrid(10, 1.0);
EndMode3D();

DrawText('Use the UP/DOWN arrow keys to switch animation', 10, 10, 20, GRAY);
DrawText('Use the ''Z'' or ''X'' keys to switch animation', 10, 10, 20, GRAY);
DrawText(TextFormat('Animation: %s', anim.name), 10, GetScreenHeight() - 20, 10, DARKGRAY);
EndDrawing();
end;
Expand Down
Loading

0 comments on commit b780b72

Please sign in to comment.