| 27 | #endif |
| 28 | |
| 29 | int main(void) |
| 30 | { |
| 31 | // Initialization |
| 32 | //-------------------------------------------------------------------------------------- |
| 33 | const int screenWidth = 800; |
| 34 | const int screenHeight = 450; |
| 35 | |
| 36 | raylib::Window window(screenWidth, screenHeight, "raylib-cpp [shaders] example - texture waves"); |
| 37 | |
| 38 | // Load texture texture to apply shaders |
| 39 | raylib::Texture2D texture("resources/space.png"); |
| 40 | |
| 41 | // Load shader and setup location points and values |
| 42 | raylib::Shader shader(0, TextFormat("resources/shaders/glsl%i/wave.fs", GLSL_VERSION)); |
| 43 | |
| 44 | int secondsLoc = shader.GetLocation("secondes"); |
| 45 | int freqXLoc = shader.GetLocation("freqX"); |
| 46 | int freqYLoc = shader.GetLocation("freqY"); |
| 47 | int ampXLoc = shader.GetLocation("ampX"); |
| 48 | int ampYLoc = shader.GetLocation("ampY"); |
| 49 | int speedXLoc = shader.GetLocation("speedX"); |
| 50 | int speedYLoc = shader.GetLocation("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)window.GetWidth(), (float)window.GetHeight() }; |
| 61 | shader.SetValue(shader.GetLocation("size"), &screenSize, SHADER_UNIFORM_VEC2); |
| 62 | shader.SetValue(freqXLoc, &freqX, SHADER_UNIFORM_FLOAT); |
| 63 | shader.SetValue(freqYLoc, &freqY, SHADER_UNIFORM_FLOAT); |
| 64 | shader.SetValue(ampXLoc, &X, SHADER_UNIFORM_FLOAT); |
| 65 | shader.SetValue(ampYLoc, &Y, SHADER_UNIFORM_FLOAT); |
| 66 | shader.SetValue(speedXLoc, &speedX, SHADER_UNIFORM_FLOAT); |
| 67 | shader.SetValue(speedYLoc, &speedY, SHADER_UNIFORM_FLOAT); |
| 68 | |
| 69 | float seconds = 0.0f; |
| 70 | |
| 71 | window.SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
| 72 | // ------------------------------------------------------------------------------------------------------------- |
| 73 | |
| 74 | // Main game loop |
| 75 | while (!window.ShouldClose()) // Detect window close button or ESC key |
| 76 | { |
| 77 | // Update |
| 78 | //---------------------------------------------------------------------------------- |
| 79 | seconds += GetFrameTime(); |
| 80 | |
| 81 | shader.SetValue(secondsLoc, &seconds, SHADER_UNIFORM_FLOAT); |
| 82 | //---------------------------------------------------------------------------------- |
| 83 | |
| 84 | // Draw |
| 85 | //---------------------------------------------------------------------------------- |
| 86 | BeginDrawing(); |
nothing calls this directly
no test coverage detected