diff options
| author | Ray <[email protected]> | 2019-05-21 17:03:01 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-05-21 17:03:01 +0200 |
| commit | 6f4a27cc61f12d3789729413bed69e86226911cf (patch) | |
| tree | 92a23884870826e6deaf560743ebbdae8bce94ba /examples/src/shaders | |
| parent | 2141d7943b6b65fa66f583f0819bb27fee815189 (diff) | |
| download | raylib.com-6f4a27cc61f12d3789729413bed69e86226911cf.tar.gz raylib.com-6f4a27cc61f12d3789729413bed69e86226911cf.zip | |
Remove examples default code
Code is directly fetched form raylib repo, this way we avoid duplicate code!
Diffstat (limited to 'examples/src/shaders')
| -rw-r--r-- | examples/src/shaders/shaders_custom_uniform.c | 136 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_eratosthenes.c | 94 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_julia_set.c | 190 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_model_shader.c | 103 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_palette_switch.c | 147 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_postprocessing.c | 182 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_raymarching.c | 112 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_shapes_textures.c | 116 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_texture_drawing.c | 80 | ||||
| -rw-r--r-- | examples/src/shaders/shaders_texture_waves.c | 110 |
10 files changed, 0 insertions, 1270 deletions
diff --git a/examples/src/shaders/shaders_custom_uniform.c b/examples/src/shaders/shaders_custom_uniform.c deleted file mode 100644 index 1c82bba..0000000 --- a/examples/src/shaders/shaders_custom_uniform.c +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************************* -* -* raylib [shaders] example - Apply a postprocessing shader and connect a custom uniform variable -* -* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, -* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. -* -* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example -* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders -* raylib comes with shaders ready for both versions, check raylib/shaders install folder -* -* This example has been created using raylib 1.3 (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" - -#if defined(PLATFORM_DESKTOP) - #define GLSL_VERSION 330 -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - #define GLSL_VERSION 100 -#endif - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable"); - - // Define the camera to look into our 3d world - Camera camera = { 0 }; - camera.position = (Vector3){ 8.0f, 8.0f, 8.0f }; - camera.target = (Vector3){ 0.0f, 1.5f, 0.0f }; - camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; - camera.fovy = 45.0f; - camera.type = CAMERA_PERSPECTIVE; - - Model model = LoadModel("resources/models/barracks.obj"); // Load OBJ model - Texture2D texture = LoadTexture("resources/models/barracks_diffuse.png"); // Load model texture (diffuse map) - model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture - - Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position - - // Load postprocessing shader - // NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader - Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/swirl.fs", GLSL_VERSION)); - - // Get variable (uniform) location on the shader to connect with the program - // NOTE: If uniform variable could not be found in the shader, function returns -1 - int swirlCenterLoc = GetShaderLocation(shader, "center"); - - float swirlCenter[2] = { (float)screenWidth/2, (float)screenHeight/2 }; - - // Create a RenderTexture2D to be used for render to texture - RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); - - // Setup orbital camera - SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - Vector2 mousePosition = GetMousePosition(); - - swirlCenter[0] = mousePosition.x; - swirlCenter[1] = screenHeight - mousePosition.y; - - // Send new value to the shader to be used on drawing - SetShaderValue(shader, swirlCenterLoc, swirlCenter, UNIFORM_VEC2); - - UpdateCamera(&camera); // Update camera - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginTextureMode(target); // Enable drawing to texture - - ClearBackground(RAYWHITE); // Clear texture background - - BeginMode3D(camera); // Begin 3d mode drawing - - DrawModel(model, position, 0.5f, WHITE); // Draw 3d model with texture - - DrawGrid(10, 1.0f); // Draw a grid - - EndMode3D(); // End 3d mode drawing, returns to orthographic 2d mode - - DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, RED); - - EndTextureMode(); // End drawing to texture (now we have a texture available for next passes) - - BeginShaderMode(shader); - - // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) - DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE); - - EndShaderMode(); - - // Draw some 2d text over drawn texture - DrawText("(c) Barracks 3D model by Alberto Cano", screenWidth - 220, screenHeight - 20, 10, GRAY); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader - UnloadTexture(texture); // Unload texture - UnloadModel(model); // Unload model - UnloadRenderTexture(target); // Unload render texture - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/shaders/shaders_eratosthenes.c b/examples/src/shaders/shaders_eratosthenes.c deleted file mode 100644 index 068fc26..0000000 --- a/examples/src/shaders/shaders_eratosthenes.c +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************************* -* -* raylib [shaders] example - Sieve of Eratosthenes -* -* Sieve of Eratosthenes, the earliest known (ancient Greek) prime number sieve. -* -* "Sift the twos and sift the threes, -* The Sieve of Eratosthenes. -* When the multiples sublime, -* the numbers that are left are prime." -* -* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, -* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. -* -* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3). -* -* This example has been created using raylib 2.5 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Example contributed by ProfJski and reviewed by Ramon Santamaria (@raysan5) -* -* Copyright (c) 2019 ProfJski and Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#if defined(PLATFORM_DESKTOP) - #define GLSL_VERSION 330 -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - #define GLSL_VERSION 100 -#endif - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Sieve of Eratosthenes"); - - RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); - - // Load Eratosthenes shader - // NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader - Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/eratosthenes.fs", GLSL_VERSION)); - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - // Nothing to do here, everything is happening in the shader - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginTextureMode(target); // Enable drawing to texture - ClearBackground(BLACK); // Clear the render texture - - // Draw a rectangle in shader mode to be used as shader canvas - // NOTE: Rectangle uses font white character texture coordinates, - // so shader can not be applied here directly because input vertexTexCoord - // do not represent full screen coordinates (space where want to apply shader) - DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK); - EndTextureMode(); // End drawing to texture (now we have a blank texture available for the shader) - - BeginShaderMode(shader); - // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) - DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0.0f, 0.0f }, WHITE); - EndShaderMode(); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader - UnloadRenderTexture(target); // Unload texture - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/src/shaders/shaders_julia_set.c b/examples/src/shaders/shaders_julia_set.c deleted file mode 100644 index e64b622..0000000 --- a/examples/src/shaders/shaders_julia_set.c +++ /dev/null @@ -1,190 +0,0 @@ -/******************************************************************************************* -* -* raylib [shaders] example - julia sets -* -* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, -* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. -* -* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3). -* -* This example has been created using raylib 2.5 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Example contributed by eggmund (@eggmund) and reviewed by Ramon Santamaria (@raysan5) -* -* Copyright (c) 2019 eggmund (@eggmund) and Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#if defined(PLATFORM_DESKTOP) - #define GLSL_VERSION 330 -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - #define GLSL_VERSION 100 -#endif - -// A few good julia sets -const float POINTS_OF_INTEREST[6][2] = -{ - { -0.348827, 0.607167 }, - { -0.786268, 0.169728 }, - { -0.8, 0.156 }, - { 0.285, 0.0 }, - { -0.835, -0.2321 }, - { -0.70176, -0.3842 }, -}; - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - julia sets"); - - // Load julia set shader - // NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader - Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/julia_set.fs", GLSL_VERSION)); - - // c constant to use in z^2 + c - float c[2] = { POINTS_OF_INTEREST[0][0], POINTS_OF_INTEREST[0][1] }; - - // Offset and zoom to draw the julia set at. (centered on screen and default size) - float offset[2] = { -(float)screenWidth/2, -(float)screenHeight/2 }; - float zoom = 1.0f; - - Vector2 offsetSpeed = { 0.0f, 0.0f }; - - // Get variable (uniform) locations on the shader to connect with the program - // NOTE: If uniform variable could not be found in the shader, function returns -1 - int cLoc = GetShaderLocation(shader, "c"); - int zoomLoc = GetShaderLocation(shader, "zoom"); - int offsetLoc = GetShaderLocation(shader, "offset"); - - // Tell the shader what the screen dimensions, zoom, offset and c are - float screenDims[2] = { (float)screenWidth, (float)screenHeight }; - SetShaderValue(shader, GetShaderLocation(shader, "screenDims"), screenDims, UNIFORM_VEC2); - - SetShaderValue(shader, cLoc, c, UNIFORM_VEC2); - SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT); - SetShaderValue(shader, offsetLoc, offset, UNIFORM_VEC2); - - // Create a RenderTexture2D to be used for render to texture - RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); - - int incrementSpeed = 0; // Multiplier of speed to change c value - bool showControls = true; // Show controls - bool pause = false; // Pause animation - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - // Press [1 - 6] to reset c to a point of interest - if (IsKeyPressed(KEY_ONE) || - IsKeyPressed(KEY_TWO) || - IsKeyPressed(KEY_THREE) || - IsKeyPressed(KEY_FOUR) || - IsKeyPressed(KEY_FIVE) || - IsKeyPressed(KEY_SIX)) - { - if (IsKeyPressed(KEY_ONE)) c[0] = POINTS_OF_INTEREST[0][0], c[1] = POINTS_OF_INTEREST[0][1]; - else if (IsKeyPressed(KEY_TWO)) c[0] = POINTS_OF_INTEREST[1][0], c[1] = POINTS_OF_INTEREST[1][1]; - else if (IsKeyPressed(KEY_THREE)) c[0] = POINTS_OF_INTEREST[2][0], c[1] = POINTS_OF_INTEREST[2][1]; - else if (IsKeyPressed(KEY_FOUR)) c[0] = POINTS_OF_INTEREST[3][0], c[1] = POINTS_OF_INTEREST[3][1]; - else if (IsKeyPressed(KEY_FIVE)) c[0] = POINTS_OF_INTEREST[4][0], c[1] = POINTS_OF_INTEREST[4][1]; - else if (IsKeyPressed(KEY_SIX)) c[0] = POINTS_OF_INTEREST[5][0], c[1] = POINTS_OF_INTEREST[5][1]; - - SetShaderValue(shader, cLoc, c, UNIFORM_VEC2); - } - - if (IsKeyPressed(KEY_SPACE)) pause = !pause; // Pause animation (c change) - if (IsKeyPressed(KEY_F1)) showControls = !showControls; // Toggle whether or not to show controls - - if (!pause) - { - if (IsKeyPressed(KEY_RIGHT)) incrementSpeed++; - else if (IsKeyPressed(KEY_LEFT)) incrementSpeed--; - - // TODO: The idea is to zoom and move around with mouse - // Probably offset movement should be proportional to zoom level - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) || IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) - { - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) zoom += zoom*0.003f; - if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) zoom -= zoom*0.003f; - - Vector2 mousePos = GetMousePosition(); - - offsetSpeed.x = mousePos.x -(float)screenWidth/2; - offsetSpeed.y = mousePos.y -(float)screenHeight/2; - - // Slowly move camera to targetOffset - offset[0] += GetFrameTime()*offsetSpeed.x*0.8f; - offset[1] += GetFrameTime()*offsetSpeed.y*0.8f; - } - else offsetSpeed = (Vector2){ 0.0f, 0.0f }; - - SetShaderValue(shader, zoomLoc, &zoom, UNIFORM_FLOAT); - SetShaderValue(shader, offsetLoc, offset, UNIFORM_VEC2); - - // Increment c value with time - float amount = GetFrameTime()*incrementSpeed*0.0005f; - c[0] += amount; - c[1] += amount; - - SetShaderValue(shader, cLoc, c, UNIFORM_VEC2); - } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(BLACK); // Clear the screen of the previous frame. - - // Using a render texture to draw Julia set - BeginTextureMode(target); // Enable drawing to texture - ClearBackground(BLACK); // Clear the render texture - - // Draw a rectangle in shader mode to be used as shader canvas - // NOTE: Rectangle uses font white character texture coordinates, - // so shader can not be applied here directly because input vertexTexCoord - // do not represent full screen coordinates (space where want to apply shader) - DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK); - EndTextureMode(); - - // Draw the saved texture and rendered julia set with shader - // NOTE: We do not invert texture on Y, already considered inside shader - BeginShaderMode(shader); - DrawTexture(target.texture, 0, 0, WHITE); - EndShaderMode(); - - if (showControls) - { - DrawText("Press Mouse buttons right/left to zoom in/out and move", 10, 15, 10, RAYWHITE); - DrawText("Press KEY_F1 to toggle these controls", 10, 30, 10, RAYWHITE); - DrawText("Press KEYS [1 - 6] to change point of interest", 10, 45, 10, RAYWHITE); - DrawText("Press KEY_LEFT | KEY_RIGHT to change speed", 10, 60, 10, RAYWHITE); - DrawText("Press KEY_SPACE to pause movement animation", 10, 75, 10, RAYWHITE); - } - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader - UnloadRenderTexture(target); // Unload render texture - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/src/shaders/shaders_model_shader.c b/examples/src/shaders/shaders_model_shader.c deleted file mode 100644 index 8224a33..0000000 --- a/examples/src/shaders/shaders_model_shader.c +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************************* -* -* raylib [shaders] example - Apply a shader to a 3d model -* -* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, -* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. -* -* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example -* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders -* raylib comes with shaders ready for both versions, check raylib/shaders install folder -* -* This example has been created using raylib 1.3 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2014 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#if defined(PLATFORM_DESKTOP) - #define GLSL_VERSION 330 -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - #define GLSL_VERSION 100 -#endif - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader"); - - // Define the camera to look into our 3d world - Camera camera = { 0 }; - camera.position = (Vector3){ 4.0f, 4.0f, 4.0f }; - camera.target = (Vector3){ 0.0f, 1.0f, -1.0f }; - camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; - camera.fovy = 45.0f; - camera.type = CAMERA_PERSPECTIVE; - - Model model = LoadModel("resources/models/watermill.obj"); // Load OBJ model - Texture2D texture = LoadTexture("resources/models/watermill_diffuse.png"); // Load model texture - - // Load shader for model - // NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader - Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION)); - - model.materials[0].shader = shader; // Set shader effect to 3d model - model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Bind texture to model - - Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position - - SetCameraMode(camera, CAMERA_FREE); // Set an orbital camera mode - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update camera - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginMode3D(camera); - - DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture - - DrawGrid(10, 1.0f); // Draw a grid - - EndMode3D(); - - DrawText("(c) Watermill 3D model by Alberto Cano", screenWidth - 210, screenHeight - 20, 10, GRAY); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader - UnloadTexture(texture); // Unload texture - UnloadModel(model); // Unload model - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/shaders/shaders_palette_switch.c b/examples/src/shaders/shaders_palette_switch.c deleted file mode 100644 index 05e2e50..0000000 --- a/examples/src/shaders/shaders_palette_switch.c +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************************* -* -* raylib [shaders] example - Color palette switch -* -* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, -* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. -* -* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example -* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders -* raylib comes with shaders ready for both versions, check raylib/shaders install folder -* -* This example has been created using raylib 2.3 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Example contributed by Marco Lizza (@MarcoLizza) and reviewed by Ramon Santamaria (@raysan5) -* -* Copyright (c) 2019 Marco Lizza (@MarcoLizza) and Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#if defined(PLATFORM_DESKTOP) - #define GLSL_VERSION 330 -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - #define GLSL_VERSION 100 -#endif - -#define MAX_PALETTES 3 -#define COLORS_PER_PALETTE 8 -#define VALUES_PER_COLOR 3 - -static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE*VALUES_PER_COLOR] = { - { // 3-BIT RGB - 0, 0, 0, - 255, 0, 0, - 0, 255, 0, - 0, 0, 255, - 0, 255, 255, - 255, 0, 255, - 255, 255, 0, - 255, 255, 255, - }, - { // AMMO-8 (GameBoy-like) - 4, 12, 6, - 17, 35, 24, - 30, 58, 41, - 48, 93, 66, - 77, 128, 97, - 137, 162, 87, - 190, 220, 127, - 238, 255, 204, - }, - { // RKBV (2-strip film) - 21, 25, 26, - 138, 76, 88, - 217, 98, 117, - 230, 184, 193, - 69, 107, 115, - 75, 151, 166, - 165, 189, 194, - 255, 245, 247, - } -}; - -static const char *paletteText[] = { - "3-BIT RGB", - "AMMO-8 (GameBoy-like)", - "RKBV (2-strip film)" -}; - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - color palette switch"); - - // Load shader to be used on some parts drawing - // NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version - // NOTE 2: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader - Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/palette_switch.fs", GLSL_VERSION)); - - // Get variable (uniform) location on the shader to connect with the program - // NOTE: If uniform variable could not be found in the shader, function returns -1 - int paletteLoc = GetShaderLocation(shader, "palette"); - - int currentPalette = 0; - int lineHeight = screenHeight/COLORS_PER_PALETTE; - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - if (IsKeyPressed(KEY_RIGHT)) currentPalette++; - else if (IsKeyPressed(KEY_LEFT)) currentPalette--; - - if (currentPalette >= MAX_PALETTES) currentPalette = 0; - else if (currentPalette < 0) currentPalette = MAX_PALETTES - 1; - - // Send new value to the shader to be used on drawing. - // NOTE: We are sending RGB triplets w/o the alpha channel - SetShaderValueV(shader, paletteLoc, palettes[currentPalette], UNIFORM_IVEC3, COLORS_PER_PALETTE); - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginShaderMode(shader); - - for (int i = 0; i < COLORS_PER_PALETTE; i++) - { - // Draw horizontal screen-wide rectangles with increasing "palette index" - // The used palette index is encoded in the RGB components of the pixel - DrawRectangle(0, lineHeight*i, GetScreenWidth(), lineHeight, (Color){ i, i, i, 255 }); - } - - EndShaderMode(); - - DrawText("< >", 10, 10, 30, DARKBLUE); - DrawText("CURRENT PALETTE:", 60, 15, 20, RAYWHITE); - DrawText(paletteText[currentPalette], 300, 15, 20, RED); - - DrawFPS(700, 15); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/src/shaders/shaders_postprocessing.c b/examples/src/shaders/shaders_postprocessing.c deleted file mode 100644 index 018b8d1..0000000 --- a/examples/src/shaders/shaders_postprocessing.c +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************************* -* -* raylib [shaders] example - Apply a postprocessing shader to a scene -* -* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, -* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. -* -* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example -* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders -* raylib comes with shaders ready for both versions, check raylib/shaders install folder -* -* This example has been created using raylib 1.3 (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" - -#if defined(PLATFORM_DESKTOP) - #define GLSL_VERSION 330 -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - #define GLSL_VERSION 100 -#endif - -#define MAX_POSTPRO_SHADERS 12 - -typedef enum { - FX_GRAYSCALE = 0, - FX_POSTERIZATION, - FX_DREAM_VISION, - FX_PIXELIZER, - FX_CROSS_HATCHING, - FX_CROSS_STITCHING, - FX_PREDATOR_VIEW, - FX_SCANLINES, - FX_FISHEYE, - FX_SOBEL, - FX_BLOOM, - FX_BLUR, - //FX_FXAA -} PostproShader; - -static const char *postproShaderText[] = { - "GRAYSCALE", - "POSTERIZATION", - "DREAM_VISION", - "PIXELIZER", - "CROSS_HATCHING", - "CROSS_STITCHING", - "PREDATOR_VIEW", - "SCANLINES", - "FISHEYE", - "SOBEL", - "BLOOM", - "BLUR", - //"FXAA" -}; - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader"); - - // Define the camera to look into our 3d world - Camera camera = {{ 2.0f, 3.0f, 2.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; - - Model model = LoadModel("resources/models/church.obj"); // Load OBJ model - Texture2D texture = LoadTexture("resources/models/church_diffuse.png"); // Load model texture (diffuse map) - model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture - - Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position - - // Load all postpro shaders - // NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER) - // NOTE 2: We load the correct shader depending on GLSL version - Shader shaders[MAX_POSTPRO_SHADERS]; - - // NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader - shaders[FX_GRAYSCALE] = LoadShader(0, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION)); - shaders[FX_POSTERIZATION] = LoadShader(0, FormatText("resources/shaders/glsl%i/posterization.fs", GLSL_VERSION)); - shaders[FX_DREAM_VISION] = LoadShader(0, FormatText("resources/shaders/glsl%i/dream_vision.fs", GLSL_VERSION)); - shaders[FX_PIXELIZER] = LoadShader(0, FormatText("resources/shaders/glsl%i/pixelizer.fs", GLSL_VERSION)); - shaders[FX_CROSS_HATCHING] = LoadShader(0, FormatText("resources/shaders/glsl%i/cross_hatching.fs", GLSL_VERSION)); - shaders[FX_CROSS_STITCHING] = LoadShader(0, FormatText("resources/shaders/glsl%i/cross_stitching.fs", GLSL_VERSION)); - shaders[FX_PREDATOR_VIEW] = LoadShader(0, FormatText("resources/shaders/glsl%i/predator.fs", GLSL_VERSION)); - shaders[FX_SCANLINES] = LoadShader(0, FormatText("resources/shaders/glsl%i/scanlines.fs", GLSL_VERSION)); - shaders[FX_FISHEYE] = LoadShader(0, FormatText("resources/shaders/glsl%i/fisheye.fs", GLSL_VERSION)); - shaders[FX_SOBEL] = LoadShader(0, FormatText("resources/shaders/glsl%i/sobel.fs", GLSL_VERSION)); - shaders[FX_BLOOM] = LoadShader(0, FormatText("resources/shaders/glsl%i/bloom.fs", GLSL_VERSION)); - shaders[FX_BLUR] = LoadShader(0, FormatText("resources/shaders/glsl%i/blur.fs", GLSL_VERSION)); - - int currentShader = FX_GRAYSCALE; - - // Create a RenderTexture2D to be used for render to texture - RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); - - // Setup orbital camera - SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update camera - - if (IsKeyPressed(KEY_RIGHT)) currentShader++; - else if (IsKeyPressed(KEY_LEFT)) currentShader--; - - if (currentShader >= MAX_POSTPRO_SHADERS) currentShader = 0; - else if (currentShader < 0) currentShader = MAX_POSTPRO_SHADERS - 1; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginTextureMode(target); // Enable drawing to texture - - ClearBackground(RAYWHITE); // Clear texture background - - BeginMode3D(camera); // Begin 3d mode drawing - - DrawModel(model, position, 0.1f, WHITE); // Draw 3d model with texture - - DrawGrid(10, 1.0f); // Draw a grid - - EndMode3D(); // End 3d mode drawing, returns to orthographic 2d mode - - EndTextureMode(); // End drawing to texture (now we have a texture available for next passes) - - // Render previously generated texture using selected postpro shader - BeginShaderMode(shaders[currentShader]); - - // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) - DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE); - - EndShaderMode(); - - // Draw 2d shapes and text over drawn texture - DrawRectangle(0, 9, 580, 30, Fade(LIGHTGRAY, 0.7f)); - - DrawText("(c) Church 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY); - - DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, BLACK); - DrawText(postproShaderText[currentShader], 330, 15, 20, RED); - DrawText("< >", 540, 10, 30, DARKBLUE); - - DrawFPS(700, 15); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - - // Unload all postpro shaders - for (int i = 0; i < MAX_POSTPRO_SHADERS; i++) UnloadShader(shaders[i]); - - UnloadTexture(texture); // Unload texture - UnloadModel(model); // Unload model - UnloadRenderTexture(target); // Unload render texture - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/src/shaders/shaders_raymarching.c b/examples/src/shaders/shaders_raymarching.c deleted file mode 100644 index 3409179..0000000 --- a/examples/src/shaders/shaders_raymarching.c +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************************* -* -* raylib [shaders] example - Raymarching shapes generation -* -* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, -* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. -* -* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example -* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders -* raylib comes with shaders ready for both versions, check raylib/shaders install folder -* -* This example has been created using raylib 2.0 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2018 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#if defined(PLATFORM_DESKTOP) - #define GLSL_VERSION 330 -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - #define GLSL_VERSION 100 -#endif - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - raymarching shapes"); - - Camera camera = { 0 }; - camera.position = (Vector3){ 2.5f, 2.5f, 3.0f }; // Camera position - camera.target = (Vector3){ 0.0f, 0.0f, 0.7f }; // Camera looking at point - camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) - camera.fovy = 65.0f; // Camera field-of-view Y - - SetCameraMode(camera, CAMERA_FREE); // Set camera mode - - // Load raymarching shader - // NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader - Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/raymarching.fs", GLSL_VERSION)); - - // Get shader locations for required uniforms - int viewEyeLoc = GetShaderLocation(shader, "viewEye"); - int viewCenterLoc = GetShaderLocation(shader, "viewCenter"); - int viewUpLoc = GetShaderLocation(shader, "viewUp"); - int deltaTimeLoc = GetShaderLocation(shader, "deltaTime"); - int runTimeLoc = GetShaderLocation(shader, "runTime"); - int resolutionLoc = GetShaderLocation(shader, "resolution"); - - float resolution[2] = { screenWidth, screenHeight }; - SetShaderValue(shader, resolutionLoc, resolution, UNIFORM_VEC2); - - float runTime = 0.0f; - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update camera - - float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z }; - float cameraTarget[3] = { camera.target.x, camera.target.y, camera.target.z }; - float cameraUp[3] = { camera.up.x, camera.up.y, camera.up.z }; - - float deltaTime = GetFrameTime(); - runTime += deltaTime; - - // Set shader required uniform values - SetShaderValue(shader, viewEyeLoc, cameraPos, UNIFORM_VEC3); - SetShaderValue(shader, viewCenterLoc, cameraTarget, UNIFORM_VEC3); - SetShaderValue(shader, viewUpLoc, cameraUp, UNIFORM_VEC3); - SetShaderValue(shader, deltaTimeLoc, &deltaTime, UNIFORM_FLOAT); - SetShaderValue(shader, runTimeLoc, &runTime, UNIFORM_FLOAT); - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - // We only draw a white full-screen rectangle, - // frame is generated in shader using raymarching - BeginShaderMode(shader); - DrawRectangle(0, 0, screenWidth, screenHeight, WHITE); - EndShaderMode(); - - DrawText("(c) Raymarching shader by Iñigo Quilez. MIT License.", screenWidth - 280, screenHeight - 20, 10, GRAY); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/shaders/shaders_shapes_textures.c b/examples/src/shaders/shaders_shapes_textures.c deleted file mode 100644 index cf53bf9..0000000 --- a/examples/src/shaders/shaders_shapes_textures.c +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************************* -* -* raylib [shaders] example - Apply a shader to some shape or texture -* -* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, -* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. -* -* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example -* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders -* raylib comes with shaders ready for both versions, check raylib/shaders install folder -* -* This example has been created using raylib 1.7 (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" - -#if defined(PLATFORM_DESKTOP) - #define GLSL_VERSION 330 -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - #define GLSL_VERSION 100 -#endif - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders"); - - Texture2D fudesumi = LoadTexture("resources/fudesumi.png"); - - // Load shader to be used on some parts drawing - // NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version - // NOTE 2: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader - Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION)); - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - // TODO: Update your variables here - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - // Start drawing with default shader - - DrawText("USING DEFAULT SHADER", 20, 40, 10, RED); - - DrawCircle(80, 120, 35, DARKBLUE); - DrawCircleGradient(80, 220, 60, GREEN, SKYBLUE); - DrawCircleLines(80, 340, 80, DARKBLUE); - - - // Activate our custom shader to be applied on next shapes/textures drawings - BeginShaderMode(shader); - - DrawText("USING CUSTOM SHADER", 190, 40, 10, RED); - - DrawRectangle(250 - 60, 90, 120, 60, RED); - DrawRectangleGradientH(250 - 90, 170, 180, 130, MAROON, GOLD); - DrawRectangleLines(250 - 40, 320, 80, 60, ORANGE); - - // Activate our default shader for next drawings - EndShaderMode(); - - DrawText("USING DEFAULT SHADER", 370, 40, 10, RED); - - DrawTriangle((Vector2){430, 80}, - (Vector2){430 - 60, 150}, - (Vector2){430 + 60, 150}, VIOLET); - - DrawTriangleLines((Vector2){430, 160}, - (Vector2){430 - 20, 230}, - (Vector2){430 + 20, 230}, DARKBLUE); - - DrawPoly((Vector2){430, 320}, 6, 80, 0, BROWN); - - // Activate our custom shader to be applied on next shapes/textures drawings - BeginShaderMode(shader); - - DrawTexture(fudesumi, 500, -30, WHITE); // Using custom shader - - // Activate our default shader for next drawings - EndShaderMode(); - - DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight - 20, 10, GRAY); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader - UnloadTexture(fudesumi); // Unload texture - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/src/shaders/shaders_texture_drawing.c b/examples/src/shaders/shaders_texture_drawing.c deleted file mode 100644 index 697000b..0000000 --- a/examples/src/shaders/shaders_texture_drawing.c +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Texture drawing -* -* This example illustrates how to draw on a blank texture using a shader -* -* This example has been created using raylib 2.0 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Example contributed by Michał Ciesielski and reviewed by Ramon Santamaria (@raysan5) -* -* Copyright (c) 2019 Michał Ciesielski and Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#if defined(PLATFORM_DESKTOP) - #define GLSL_VERSION 330 -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - #define GLSL_VERSION 100 -#endif - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture drawing"); - - Image imBlank = GenImageColor(1024, 1024, BLANK); - Texture2D texture = LoadTextureFromImage(imBlank); // Load blank texture to fill on shader - UnloadImage(imBlank); - - // NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version - Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/cubes_panning.fs", GLSL_VERSION)); - - float time = 0.0f; - int timeLoc = GetShaderLocation(shader, "uTime"); - SetShaderValue(shader, timeLoc, &time, UNIFORM_FLOAT); - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - // ------------------------------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - time = GetTime(); - SetShaderValue(shader, timeLoc, &time, UNIFORM_FLOAT); - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginShaderMode(shader); // Enable our custom shader for next shapes/textures drawings - DrawTexture(texture, 0, 0, WHITE); // Drawing BLANK texture, all magic happens on shader - EndShaderMode(); // Disable our custom shader, return to default shader - - DrawText("BACKGROUND is PAINTED and ANIMATED on SHADER!", 10, 10, 20, MAROON); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadShader(shader); - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/src/shaders/shaders_texture_waves.c b/examples/src/shaders/shaders_texture_waves.c deleted file mode 100644 index 07186d3..0000000 --- a/examples/src/shaders/shaders_texture_waves.c +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************************* -* -* raylib [shaders] example - Texture Waves -* -* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, -* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. -* -* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example -* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders -* raylib comes with shaders ready for both versions, check raylib/shaders install folder -* -* This example has been created using raylib 2.5 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Example contributed by Anata (@anatagawa) and reviewed by Ramon Santamaria (@raysan5) -* -* Copyright (c) 2019 Anata (@anatagawa) and Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#if defined(PLATFORM_DESKTOP) - #define GLSL_VERSION 330 -#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB - #define GLSL_VERSION 100 -#endif - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture waves"); - - // Load texture texture to apply shaders - Texture2D texture = LoadTexture("resources/space.png"); - - // Load shader and setup location points and values - Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/wave.fs", GLSL_VERSION)); - - int secondsLoc = GetShaderLocation(shader, "secondes"); - int freqXLoc = GetShaderLocation(shader, "freqX"); - int freqYLoc = GetShaderLocation(shader, "freqY"); - int ampXLoc = GetShaderLocation(shader, "ampX"); - int ampYLoc = GetShaderLocation(shader, "ampY"); - int speedXLoc = GetShaderLocation(shader, "speedX"); - int speedYLoc = GetShaderLocation(shader, "speedY"); - - // Shader uniform values that can be updated at any time - float freqX = 25.0f; - float freqY = 25.0f; - float ampX = 5.0f; - float ampY = 5.0f; - float speedX = 8.0f; - float speedY = 8.0f; - - float screenSize[2] = { (float)GetScreenWidth(), (float)GetScreenHeight() }; - SetShaderValue(shader, GetShaderLocation(shader, "size"), &screenSize, UNIFORM_VEC2); - SetShaderValue(shader, freqXLoc, &freqX, UNIFORM_FLOAT); - SetShaderValue(shader, freqYLoc, &freqY, UNIFORM_FLOAT); - SetShaderValue(shader, ampXLoc, &X, UNIFORM_FLOAT); - SetShaderValue(shader, ampYLoc, &Y, UNIFORM_FLOAT); - SetShaderValue(shader, speedXLoc, &speedX, UNIFORM_FLOAT); - SetShaderValue(shader, speedYLoc, &speedY, UNIFORM_FLOAT); - - float seconds = 0.0f; - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - // ------------------------------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - seconds += GetFrameTime(); - - SetShaderValue(shader, secondsLoc, &seconds, UNIFORM_FLOAT); - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - BeginShaderMode(shader); - - DrawTexture(texture, 0, 0, WHITE); - DrawTexture(texture, texture.width, 0, WHITE); - - EndShaderMode(); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader - UnloadTexture(texture); // Unload texture - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} |
