diff options
| author | LLLL Colonq <llll@colonq> | 2025-01-15 21:21:22 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2025-01-15 21:21:22 -0500 |
| commit | 82d1c94d999654bda5d40108393eade80b77342c (patch) | |
| tree | 2a05c0ffe34ba47933ca39ebef3c3609fb6a5d2a /src/assets/shaders/truetype | |
| parent | f1b47ccb8a92280df51bb28b495829f8f7f8127e (diff) | |
Update
Diffstat (limited to 'src/assets/shaders/truetype')
| -rw-r--r-- | src/assets/shaders/truetype/frag.glsl | 23 | ||||
| -rw-r--r-- | src/assets/shaders/truetype/vert.glsl | 26 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/assets/shaders/truetype/frag.glsl b/src/assets/shaders/truetype/frag.glsl new file mode 100644 index 0000000..b0e25bf --- /dev/null +++ b/src/assets/shaders/truetype/frag.glsl @@ -0,0 +1,23 @@ +#version 300 es +precision highp float; + +uniform sampler2D texture_data; +uniform int text[256]; +uniform int atlas_width; +uniform int cell_width; +uniform int text_width; + +in vec2 vertex_texcoord; +out vec4 frag_color; + +void main() +{ + vec2 inverted_texcoord = vec2(vertex_texcoord.x, 1.0 - vertex_texcoord.y); + float texcoord_pixels_x = inverted_texcoord.x * float(text_width); + int char_idx = int(floor(texcoord_pixels_x)) / cell_width; + int offset = text[char_idx]; + float cbase = float(offset); + float coff = mod(texcoord_pixels_x, float(cell_width)); + float val = texture(texture_data, vec2((cbase + coff) / float(atlas_width), inverted_texcoord.y)).r; + frag_color = vec4(val, val, val, 1.0); +} diff --git a/src/assets/shaders/truetype/vert.glsl b/src/assets/shaders/truetype/vert.glsl new file mode 100644 index 0000000..4005d75 --- /dev/null +++ b/src/assets/shaders/truetype/vert.glsl @@ -0,0 +1,26 @@ +#version 300 es +precision highp float; + +uniform mat4 view; +uniform mat4 position; + +out vec2 vertex_texcoord; + +void main() { + const vec2 positions[4] = vec2[]( + vec2(-1, -1), + vec2(+1, -1), + vec2(-1, +1), + vec2(+1, +1) + ); + const vec2 coords[4] = vec2[]( + vec2(0, 0), + vec2(1, 0), + vec2(0, 1), + vec2(1, 1) + ); + vec4 vertex = vec4(positions[gl_VertexID], 0.0, 1.0); + + vertex_texcoord = coords[gl_VertexID]; + gl_Position = view * position * vertex; +} |
