-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
76 lines (49 loc) · 1.94 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Vignette shader by Apfelstrudel Technologien.
#include "raylib.h"
int main(void)
{
// Window.
const int winW = 1500;
const int winH = 1000;
InitWindow(winW, winH, "Vignette.");
// Shader loading & generic preparing.
Shader shader = LoadShader(0, "vignette.fs");
int rLoc = GetShaderLocation(shader, "radius");
int blurLoc = GetShaderLocation(shader, "blur");
int colLoc = GetShaderLocation(shader, "color");
// Radius and blur.
float radius = 0.5f;
float blur = 0.1f;
Vector3 vColor = {0.5f, 0.5f, 0.5f}; // Vignette color.
RenderTexture2D vTexture = LoadRenderTexture(winW, winH); // Vignette texture.
SetTargetFPS(60);
while (!WindowShouldClose())
{
// Update values.
if (IsKeyDown(KEY_UP)) radius += 0.01f;
if (IsKeyDown(KEY_DOWN)) radius -= 0.01f;
if (IsKeyDown(KEY_RIGHT)) blur += 0.01f;
if (IsKeyDown(KEY_LEFT)) blur -= 0.01f;
SetShaderValue(shader, rLoc, &radius, SHADER_UNIFORM_FLOAT);
SetShaderValue(shader, blurLoc, &blur, SHADER_UNIFORM_FLOAT);
SetShaderValue(shader, colLoc, &vColor, SHADER_UNIFORM_VEC3);
// Begin.
BeginDrawing();
ClearBackground(WHITE);
// Draw vignette.
BeginShaderMode(shader);
DrawTextureRec(vTexture.texture, (Rectangle){ 0, 0, vTexture.texture.width, -vTexture.texture.height }, (Vector2){ 0, 0 }, BLANK);
EndShaderMode();
// Some information.
DrawText(TextFormat("Radius: %.2f", radius), 10, 10, 20, BLACK);
DrawText(TextFormat("Blur: %.2f", blur), 10, 40, 20, BLACK);
DrawText("Use arrow keys to adjust radius and blur", 10, 70, 20, BLACK);
// End.
EndDrawing();
}
// Unload everything and close window.
UnloadShader(shader);
UnloadRenderTexture(vTexture);
CloseWindow();
return 0;
}