summaryrefslogtreecommitdiff
path: root/src/assets/shaders/bitmap/frag.glsl
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-01-18 20:46:08 -0500
committerLLLL Colonq <llll@colonq>2025-01-18 20:46:08 -0500
commit6c00c069ccf08ef5e577c16acc78a5b1f53a0f8f (patch)
treeca0cf7a5e042883cfa7fe95725d8eda35860d56e /src/assets/shaders/bitmap/frag.glsl
parent82d1c94d999654bda5d40108393eade80b77342c (diff)
Rework font rendering, configurable resolution
Diffstat (limited to 'src/assets/shaders/bitmap/frag.glsl')
-rw-r--r--src/assets/shaders/bitmap/frag.glsl46
1 files changed, 2 insertions, 44 deletions
diff --git a/src/assets/shaders/bitmap/frag.glsl b/src/assets/shaders/bitmap/frag.glsl
index 94d27c9..470a7b8 100644
--- a/src/assets/shaders/bitmap/frag.glsl
+++ b/src/assets/shaders/bitmap/frag.glsl
@@ -2,55 +2,13 @@
precision highp float;
uniform sampler2D texture_data;
-uniform int text_length;
-uniform int text[256];
-uniform int char_width;
-uniform int char_height;
-uniform int font_width;
-uniform int font_height;
-uniform int text_width;
-uniform int text_height;
uniform vec3 text_color;
in vec2 vertex_texcoord;
out vec4 frag_color;
-void main()
-{
- vec2 inverted_texcoord = vec2(vertex_texcoord.x, 1.0 - vertex_texcoord.y);
- vec2 texcoord_pixels = inverted_texcoord * vec2(float(text_width), float(text_height));
- int texcoord_char_x = int(floor(texcoord_pixels.x)) / char_width;
- int texcoord_char_y = int(floor(texcoord_pixels.y)) / char_height;
-
- int x = 0;
- int y = 0;
- int i = 0;
- for (; i < text_length; ++i) {
- if (x == texcoord_char_x && y == texcoord_char_y) {
- break;
- }
- if (text[i] == 10) {
- x = 0;
- y += 1;
- } else {
- x += 1;
- }
- }
- if (i == text_length || text[i] == 10) discard;
-
- int entry = text[i] - 32;
- vec2 texcoord_base = vec2(
- float(entry % (font_width / char_width)) * float(char_width),
- float(entry / (font_width / char_width)) * float(char_height)
- );
- // vec2 texcoord_base = vec2(8.0, 0.0);
- vec2 texcoord_off = vec2(
- mod(texcoord_pixels.x, float(char_width)),
- mod(texcoord_pixels.y, float(char_height))
- );
- vec2 texcoord_final = (texcoord_base + texcoord_off) / vec2(float(font_width), float(font_height));
-
- vec4 texel = texture(texture_data, texcoord_final);
+void main() {
+ vec4 texel = texture(texture_data, vertex_texcoord);
if (texel.rgb == vec3(0.0, 0.0, 0.0)) discard;
texel.r = text_color.r;
texel.g = text_color.g;