From 81aa75359d1444747331f0b48def800219d46db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Stensg=C3=A5rd?= Date: Sun, 20 Apr 2025 23:27:35 +0200 Subject: press f to effect text --- opplysning.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'opplysning.c') diff --git a/opplysning.c b/opplysning.c index 7155a2c..57e90b1 100644 --- a/opplysning.c +++ b/opplysning.c @@ -109,11 +109,32 @@ const char *the_alphabet = "0123456789" "ÄÅÉËÞÜÚÍÓÖÁSSÐFGHÏŒØÆŒ©®BÑΜ" "äåéëþüúíóöáßðfghïœøæœ©®bñµ" "!@#$%^&*()[];'\\:\"|,./<>?"; +Shader the_shader; +RenderTexture2D the_target; +int the_shader_u_time; +void +blur(int x, int y, Font f, Color c, char *s) +{ + const int sh = 1080; + Vector2 m = MeasureTextEx(f, s, f.baseSize, 0); + + BeginTextureMode(the_target); + ClearBackground((Color){0}); + DrawTextEx(f, s, (Vector2){0, 0}, (float)f.baseSize, 0, c); + EndTextureMode(); + + BeginShaderMode(the_shader); + float t = GetTime(); + SetShaderValue(the_shader, the_shader_u_time, &t, SHADER_UNIFORM_FLOAT); + DrawTextureRec(the_target.texture, (Rectangle){0, sh - m.y, m.x, -m.y}, + (Vector2){x, y}, WHITE); + EndShaderMode(); +} void line(int x, int y, Font f, Color c, char *s) { - DrawTextEx(f, s, (Vector2){x, y}, (float)f.baseSize, 2, c); + DrawTextEx(f, s, (Vector2){x, y}, (float)f.baseSize, 0, c); } int @@ -140,6 +161,11 @@ main(void) Color fg = BLACK; Color hd = {0xf0, 0x4a, 0x00, 0xff}; + the_shader = LoadShader(0, "s.glsl"); + the_shader_u_time = GetShaderLocation(the_shader, "u_time"); + the_target = LoadRenderTexture(sw, sh); + int fx = 0; + while (!WindowShouldClose()) { struct timespec now = {0}; clock_gettime(CLOCK_REALTIME, &now); @@ -147,6 +173,9 @@ main(void) char ts[64] = {0}; snprintf(ts, sizeof(ts), "%02d:%02d", ti->tm_hour, ti->tm_min); + if (IsKeyPressed(KEY_F)) + fx = !fx; + BeginDrawing(); ClearBackground(bg); Vector2 v2_ts = MeasureTextEx(font_h, ts, font_h.baseSize, 0); @@ -166,7 +195,10 @@ main(void) snprintf(s, sizeof(s), "%s %u. %s", ukedag[e->wday], e->day, maaned[e->month]); - line(25, y += 50, font_h, hd, s); + if (fx) + blur(25, y += 50, font_h, hd, s); + else + line(25, y += 50, font_h, hd, s); y += 20; } { -- cgit v1.2.3