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.

110 lines
4.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /*******************************************************************************************
  2. *
  3. * raylib [shaders] example - Texture Waves
  4. *
  5. * NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
  6. * OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
  7. *
  8. * NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
  9. * on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
  10. * raylib comes with shaders ready for both versions, check raylib/shaders install folder
  11. *
  12. * This example has been created using raylib 2.5 (www.raylib.com)
  13. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  14. *
  15. * Example contributed by Anata (@anatagawa) and reviewed by Ramon Santamaria (@raysan5)
  16. *
  17. * Copyright (c) 2019 Anata (@anatagawa) and Ramon Santamaria (@raysan5)
  18. *
  19. ********************************************************************************************/
  20. #include "raylib.h"
  21. #if defined(PLATFORM_DESKTOP)
  22. #define GLSL_VERSION 330
  23. #else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
  24. #define GLSL_VERSION 100
  25. #endif
  26. int main(void)
  27. {
  28. // Initialization
  29. //--------------------------------------------------------------------------------------
  30. const int screenWidth = 800;
  31. const int screenHeight = 450;
  32. InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture waves");
  33. // Load texture texture to apply shaders
  34. Texture2D texture = LoadTexture("resources/space.png");
  35. // Load shader and setup location points and values
  36. Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/wave.fs", GLSL_VERSION));
  37. int secondsLoc = GetShaderLocation(shader, "secondes");
  38. int freqXLoc = GetShaderLocation(shader, "freqX");
  39. int freqYLoc = GetShaderLocation(shader, "freqY");
  40. int ampXLoc = GetShaderLocation(shader, "ampX");
  41. int ampYLoc = GetShaderLocation(shader, "ampY");
  42. int speedXLoc = GetShaderLocation(shader, "speedX");
  43. int speedYLoc = GetShaderLocation(shader, "speedY");
  44. // Shader uniform values that can be updated at any time
  45. float freqX = 25.0f;
  46. float freqY = 25.0f;
  47. float ampX = 5.0f;
  48. float ampY = 5.0f;
  49. float speedX = 8.0f;
  50. float speedY = 8.0f;
  51. float screenSize[2] = { (float)GetScreenWidth(), (float)GetScreenHeight() };
  52. SetShaderValue(shader, GetShaderLocation(shader, "size"), &screenSize, UNIFORM_VEC2);
  53. SetShaderValue(shader, freqXLoc, &freqX, UNIFORM_FLOAT);
  54. SetShaderValue(shader, freqYLoc, &freqY, UNIFORM_FLOAT);
  55. SetShaderValue(shader, ampXLoc, &ampX, UNIFORM_FLOAT);
  56. SetShaderValue(shader, ampYLoc, &ampY, UNIFORM_FLOAT);
  57. SetShaderValue(shader, speedXLoc, &speedX, UNIFORM_FLOAT);
  58. SetShaderValue(shader, speedYLoc, &speedY, UNIFORM_FLOAT);
  59. float seconds = 0.0f;
  60. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  61. // -------------------------------------------------------------------------------------------------------------
  62. // Main game loop
  63. while (!WindowShouldClose()) // Detect window close button or ESC key
  64. {
  65. // Update
  66. //----------------------------------------------------------------------------------
  67. seconds += GetFrameTime();
  68. SetShaderValue(shader, secondsLoc, &seconds, UNIFORM_FLOAT);
  69. //----------------------------------------------------------------------------------
  70. // Draw
  71. //----------------------------------------------------------------------------------
  72. BeginDrawing();
  73. ClearBackground(RAYWHITE);
  74. BeginShaderMode(shader);
  75. DrawTexture(texture, 0, 0, WHITE);
  76. DrawTexture(texture, texture.width, 0, WHITE);
  77. EndShaderMode();
  78. EndDrawing();
  79. //----------------------------------------------------------------------------------
  80. }
  81. // De-Initialization
  82. //--------------------------------------------------------------------------------------
  83. UnloadShader(shader); // Unload shader
  84. UnloadTexture(texture); // Unload texture
  85. CloseWindow(); // Close window and OpenGL context
  86. //--------------------------------------------------------------------------------------
  87. return 0;
  88. }