diff options
| author | Ray <[email protected]> | 2019-04-11 16:53:20 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-04-11 16:53:20 +0200 |
| commit | 129703fad18b478d015a520524d46ab4afa2cb79 (patch) | |
| tree | 4155ff93f5f118ae50f11f7dcb6cc7644664f085 /examples/shaders/shaders_texture_drawing.c | |
| parent | 6fc97643bf564ec2f616ba3114230c78ed1c265e (diff) | |
| download | raylib-129703fad18b478d015a520524d46ab4afa2cb79.tar.gz raylib-129703fad18b478d015a520524d46ab4afa2cb79.zip | |
new example: shaders_texture_drawing
Diffstat (limited to 'examples/shaders/shaders_texture_drawing.c')
| -rw-r--r-- | examples/shaders/shaders_texture_drawing.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/examples/shaders/shaders_texture_drawing.c b/examples/shaders/shaders_texture_drawing.c new file mode 100644 index 00000000..cb8a9c1e --- /dev/null +++ b/examples/shaders/shaders_texture_drawing.c @@ -0,0 +1,71 @@ +/******************************************************************************************* +* +* raylib [textures] example - Shader 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) +* +* Copyright (c) 2019 MichaĆ Ciesielski and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shader 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, "resources/shaders/glsl330/cubes_panning.fs"); + + float time = 0.0f; + int timeLoc = GetShaderLocation(shader, "uTime"); + SetShaderValue(shader, timeLoc, &time, UNIFORM_FLOAT); + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + while (!WindowShouldClose()) + { + // 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; +} |
