diff options
| author | Martin Stensgård <mastensg@mastensg.net> | 2025-04-20 23:27:35 +0200 |
|---|---|---|
| committer | Martin Stensgård <mastensg@mastensg.net> | 2025-04-20 23:27:35 +0200 |
| commit | 81aa75359d1444747331f0b48def800219d46db2 (patch) | |
| tree | ccf81cf24ebc97b91259b7377ef0e258ca8de4ed | |
| parent | 79c96a5dabdb5e062b89e90d70ed36cd215300bc (diff) | |
press f to effect text
| -rw-r--r-- | opplysning.c | 36 | ||||
| -rw-r--r-- | s.glsl | 20 |
2 files changed, 54 insertions, 2 deletions
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; } { @@ -0,0 +1,20 @@ +#version 100 + +precision mediump float; + +varying vec2 fragTexCoord; +varying vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 colDiffuse; +uniform float u_time; + +void main() +{ + vec4 tex = texture2D(texture0, fragTexCoord); + vec3 a = vec3(1.0, 0.0, 1.0); + vec3 b = vec3(0.0, 1.0, 0.0); + float m = 0.5 + 0.5*(sin(0.2*gl_FragCoord.x + 5.0*u_time) + cos(0.2*gl_FragCoord.y + 5.0*u_time)); + //float m = 0.5; + gl_FragColor = vec4(mix(a, b, m), tex.a); +} |
