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
21#include "raylib.h"
22
23#if defined(PLATFORM_DESKTOP)
24 #define GLSL_VERSION 330
25#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
26 #define GLSL_VERSION 100
27#endif
28
29int main(void)
30{
31 // Initialization
32 //--------------------------------------------------------------------------------------
33 const int screenWidth = 800;
34 const int screenHeight = 450;
35
36 InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture waves");
37
38 // Load texture texture to apply shaders
39 Texture2D texture = LoadTexture("resources/space.png");
40
41 // Load shader and setup location points and values
42 Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/wave.fs", GLSL_VERSION));
43
44 int secondsLoc = GetShaderLocation(shader, "secondes");
45 int freqXLoc = GetShaderLocation(shader, "freqX");
46 int freqYLoc = GetShaderLocation(shader, "freqY");
47 int ampXLoc = GetShaderLocation(shader, "ampX");
48 int ampYLoc = GetShaderLocation(shader, "ampY");
49 int speedXLoc = GetShaderLocation(shader, "speedX");
50 int speedYLoc = GetShaderLocation(shader, "speedY");
51
52 // Shader uniform values that can be updated at any time
53 float freqX = 25.0f;
54 float freqY = 25.0f;
55 float ampX = 5.0f;
56 float ampY = 5.0f;
57 float speedX = 8.0f;
58 float speedY = 8.0f;
59
60 float screenSize[2] = { (float)GetScreenWidth(), (float)GetScreenHeight() };
61 SetShaderValue(shader, GetShaderLocation(shader, "size"), &screenSize, UNIFORM_VEC2);
62 SetShaderValue(shader, freqXLoc, &freqX, UNIFORM_FLOAT);
63 SetShaderValue(shader, freqYLoc, &freqY, UNIFORM_FLOAT);
64 SetShaderValue(shader, ampXLoc, &ampX, UNIFORM_FLOAT);
65 SetShaderValue(shader, ampYLoc, &ampY, UNIFORM_FLOAT);
66 SetShaderValue(shader, speedXLoc, &speedX, UNIFORM_FLOAT);
67 SetShaderValue(shader, speedYLoc, &speedY, UNIFORM_FLOAT);
68
69 float seconds = 0.0f;
70
71 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
72 // -------------------------------------------------------------------------------------------------------------
73
74 // Main game loop
75 while (!WindowShouldClose()) // Detect window close button or ESC key
76 {
77 // Update
78 //----------------------------------------------------------------------------------
79 seconds += GetFrameTime();
80
81 SetShaderValue(shader, secondsLoc, &seconds, UNIFORM_FLOAT);
82 //----------------------------------------------------------------------------------
83
84 // Draw
85 //----------------------------------------------------------------------------------
86 BeginDrawing();
87
88 ClearBackground(RAYWHITE);
89
90 BeginShaderMode(shader);
91
92 DrawTexture(texture, 0, 0, WHITE);
93 DrawTexture(texture, texture.width, 0, WHITE);
94
95 EndShaderMode();
96
97 EndDrawing();
98 //----------------------------------------------------------------------------------
99 }
100
101 // De-Initialization
102 //--------------------------------------------------------------------------------------
103 UnloadShader(shader); // Unload shader
104 UnloadTexture(texture); // Unload texture
105
106 CloseWindow(); // Close window and OpenGL context
107 //--------------------------------------------------------------------------------------
108
109 return 0;
110}
111