Update web examples -WORK IN PROGRESS-

This commit is contained in:
Ray 2017-04-01 00:51:31 +02:00
commit e6ed85e993
70 changed files with 1309794 additions and 1379839 deletions

View file

@ -25,6 +25,9 @@ int screenHeight = 450;
int framesCounter = 0; int framesCounter = 0;
float timePlayed = 0.0f; float timePlayed = 0.0f;
static bool pause = false;
Music music;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module Functions Declaration // Module Functions Declaration
@ -42,7 +45,9 @@ int main()
InitAudioDevice(); // Initialize audio device InitAudioDevice(); // Initialize audio device
PlayMusicStream(0, "resources/audio/guitar_noodling.ogg"); // Play music stream music = LoadMusicStream("resources/audio/guitar_noodling.ogg");
PlayMusicStream(music);
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 0, 1); emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
@ -59,6 +64,8 @@ int main()
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadMusicStream(music); // Unload music stream buffers from RAM
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -73,33 +80,26 @@ void UpdateDrawFrame(void)
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
framesCounter++; UpdateMusicStream(music); // Update music buffer with new stream data
// Testing music fading from one file to another // Restart music playing (stop and play)
/* if (IsKeyPressed(KEY_SPACE))
if (framesCounter > 600) // Wait for 10 seconds (600 frames) {
{ StopMusicStream(music);
volume -= 0.01; // Decrement music volume level PlayMusicStream(music);
}
// When music volume level equal or lower than 0, // Pause/Resume music playing
// restore volume level and init another music file if (IsKeyPressed(KEY_P))
if (volume <= 0) {
{ pause = !pause;
volume = 1.0;
framesCounter = 0;
PlayMusicStream(1, "resources/audio/another_file.ogg");
}
SetMusicVolume(volume); if (pause) PauseMusicStream(music);
} else ResumeMusicStream(music);
*/ }
if (IsWindowMinimized()) PauseMusicStream(0); // Get timePlayed scaled to bar dimensions (400 pixels)
else ResumeMusicStream(0); timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*400;
timePlayed = GetMusicTimePlayed(0)/GetMusicTimeLength(0)*100*4; // We scale by 4 to fit 400 pixels
UpdateMusicStream(0); // Update music buffer with new stream data
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
@ -108,11 +108,14 @@ void UpdateDrawFrame(void)
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY); DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY);
DrawRectangle(200, 250, 400, 12, LIGHTGRAY); DrawRectangle(200, 200, 400, 12, LIGHTGRAY);
DrawRectangle(200, 250, (int)timePlayed, 12, MAROON); DrawRectangle(200, 200, (int)timePlayed, 12, MAROON);
DrawRectangleLines(200, 200, 400, 12, GRAY);
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY);
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,114 @@
/*******************************************************************************************
*
* raylib [audio] example - Raw audio streaming
*
* NOTE: This example requires OpenAL Soft library installed
*
* This example has been created using raylib 1.6 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#include <stdlib.h> // Required for: malloc(), free()
#include <math.h> // Required for: sinf()
#define MAX_SAMPLES 22050
#define MAX_SAMPLES_PER_UPDATE 4096
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [audio] example - raw audio streaming");
InitAudioDevice(); // Initialize audio device
// Init raw audio stream (sample rate: 22050, sample size: 16bit-short, channels: 1-mono)
AudioStream stream = InitAudioStream(22050, 16, 1);
// Generate samples data from sine wave
short *data = (short *)malloc(sizeof(short)*MAX_SAMPLES);
// TODO: Review data generation, it seems data is discontinued for loop,
// for that reason, there is a clip everytime audio stream is looped...
for (int i = 0; i < MAX_SAMPLES; i++)
{
data[i] = (short)(sinf(((2*PI*(float)i)/2)*DEG2RAD)*32000);
}
PlayAudioStream(stream); // Start processing stream buffer (no data loaded currently)
int totalSamples = MAX_SAMPLES;
int samplesLeft = totalSamples;
Vector2 position = { 0, 0 };
SetTargetFPS(30); // Set our game to run at 30 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// Refill audio stream if required
// NOTE: Every update we check if stream data has been already consumed and we update
// buffer with new data from the generated samples, we upload data at a rate (MAX_SAMPLES_PER_UPDATE),
// but notice that at some point we update < MAX_SAMPLES_PER_UPDATE data...
if (IsAudioBufferProcessed(stream))
{
int numSamples = 0;
if (samplesLeft >= MAX_SAMPLES_PER_UPDATE) numSamples = MAX_SAMPLES_PER_UPDATE;
else numSamples = samplesLeft;
UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples);
samplesLeft -= numSamples;
// Reset samples feeding (loop audio)
if (samplesLeft <= 0) samplesLeft = totalSamples;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY);
// NOTE: Draw a part of the sine wave (only screen width, proportional values)
for (int i = 0; i < GetScreenWidth(); i++)
{
position.x = i;
position.y = 250 + 50*data[i]/32000;
DrawPixelV(position, RED);
}
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
free(data); // Unload sine wave data
CloseAudioStream(stream); // Close raw audio stream and delete buffers from RAM
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -56,8 +56,7 @@ int main()
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 }; colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
} }
SetCameraMode(CAMERA_FIRST_PERSON); // Set a first person camera mode SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode
SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 0, 1); emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
@ -88,7 +87,7 @@ void UpdateDrawFrame(void)
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
UpdateCameraPlayer(&camera, &playerPosition); // Update camera and player position UpdateCamera(&camera); // Update camera and player position
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw

File diff suppressed because one or more lines are too long

View file

@ -47,10 +47,7 @@ int main()
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y camera.fovy = 45.0f; // Camera field-of-view Y
SetCameraMode(CAMERA_FREE); // Set a free camera mode SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 0, 1); emscripten_set_main_loop(UpdateDrawFrame, 0, 1);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -50,9 +50,7 @@ int main()
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
camera.fovy = 45.0f; // Camera field-of-view Y camera.fovy = 45.0f; // Camera field-of-view Y
SetCameraMode(CAMERA_FREE); // Set a free camera mode SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
SetCameraFovy(camera.fovy); // Set internal camera field-of-view Y
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 0, 1); emscripten_set_main_loop(UpdateDrawFrame, 0, 1);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -42,9 +42,7 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
SetCameraMode(CAMERA_FREE); // Set a free camera mode SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 0, 1); emscripten_set_main_loop(UpdateDrawFrame, 0, 1);

Some files were not shown because too many files have changed in this diff Show more