You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.5 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. /*******************************************************************************************
  2. *
  3. * raylib [audio] example - Sound loading and playing
  4. *
  5. * NOTE: This example requires OpenAL Soft library installed
  6. *
  7. * This example has been created using raylib 1.0 (www.raylib.com)
  8. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  9. *
  10. * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. int main()
  15. {
  16. // Initialization
  17. //--------------------------------------------------------------------------------------
  18. int screenWidth = 800;
  19. int screenHeight = 450;
  20. InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
  21. InitAudioDevice(); // Initialize audio device
  22. Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
  23. Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
  24. //--------------------------------------------------------------------------------------
  25. // Main game loop
  26. while (!WindowShouldClose()) // Detect window close button or ESC key
  27. {
  28. // Update
  29. //----------------------------------------------------------------------------------
  30. if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
  31. if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
  32. //----------------------------------------------------------------------------------
  33. // Draw
  34. //----------------------------------------------------------------------------------
  35. BeginDrawing();
  36. ClearBackground(RAYWHITE);
  37. DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
  38. DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
  39. EndDrawing();
  40. //----------------------------------------------------------------------------------
  41. }
  42. // De-Initialization
  43. //--------------------------------------------------------------------------------------
  44. UnloadSound(fxWav); // Unload sound data
  45. UnloadSound(fxOgg); // Unload sound data
  46. CloseAudioDevice(); // Close audio device
  47. CloseWindow(); // Close window and OpenGL context
  48. //--------------------------------------------------------------------------------------
  49. return 0;
  50. }