1 | /******************************************************************************************* |
2 | * |
3 | * raylib [textures] example - Texture drawing |
4 | * |
5 | * This example illustrates how to draw on a blank texture using a shader |
6 | * |
7 | * This example has been created using raylib 2.0 (www.raylib.com) |
8 | * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) |
9 | * |
10 | * Example contributed by Michał Ciesielski and reviewed by Ramon Santamaria (@raysan5) |
11 | * |
12 | * Copyright (c) 2019 Michał Ciesielski and Ramon Santamaria (@raysan5) |
13 | * |
14 | ********************************************************************************************/ |
15 | |
16 | #include "raylib.h" |
17 | |
18 | #if defined(PLATFORM_DESKTOP) |
19 | #define GLSL_VERSION 330 |
20 | #else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB |
21 | #define GLSL_VERSION 100 |
22 | #endif |
23 | |
24 | int main(void) |
25 | { |
26 | // Initialization |
27 | //-------------------------------------------------------------------------------------- |
28 | const int screenWidth = 800; |
29 | const int screenHeight = 450; |
30 | |
31 | InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture drawing" ); |
32 | |
33 | Image imBlank = GenImageColor(1024, 1024, BLANK); |
34 | Texture2D texture = LoadTextureFromImage(imBlank); // Load blank texture to fill on shader |
35 | UnloadImage(imBlank); |
36 | |
37 | // NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version |
38 | Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/cubes_panning.fs" , GLSL_VERSION)); |
39 | |
40 | float time = 0.0f; |
41 | int timeLoc = GetShaderLocation(shader, "uTime" ); |
42 | SetShaderValue(shader, timeLoc, &time, UNIFORM_FLOAT); |
43 | |
44 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
45 | // ------------------------------------------------------------------------------------------------------------- |
46 | |
47 | // Main game loop |
48 | while (!WindowShouldClose()) // Detect window close button or ESC key |
49 | { |
50 | // Update |
51 | //---------------------------------------------------------------------------------- |
52 | time = GetTime(); |
53 | SetShaderValue(shader, timeLoc, &time, UNIFORM_FLOAT); |
54 | //---------------------------------------------------------------------------------- |
55 | |
56 | // Draw |
57 | //---------------------------------------------------------------------------------- |
58 | BeginDrawing(); |
59 | |
60 | ClearBackground(RAYWHITE); |
61 | |
62 | BeginShaderMode(shader); // Enable our custom shader for next shapes/textures drawings |
63 | DrawTexture(texture, 0, 0, WHITE); // Drawing BLANK texture, all magic happens on shader |
64 | EndShaderMode(); // Disable our custom shader, return to default shader |
65 | |
66 | DrawText("BACKGROUND is PAINTED and ANIMATED on SHADER!" , 10, 10, 20, MAROON); |
67 | |
68 | EndDrawing(); |
69 | //---------------------------------------------------------------------------------- |
70 | } |
71 | |
72 | // De-Initialization |
73 | //-------------------------------------------------------------------------------------- |
74 | UnloadShader(shader); |
75 | |
76 | CloseWindow(); // Close window and OpenGL context |
77 | //-------------------------------------------------------------------------------------- |
78 | |
79 | return 0; |
80 | } |
81 | |