diff options
| author | LLLL Colonq <llll@colonq> | 2025-01-21 15:27:55 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2025-01-21 15:27:55 -0500 |
| commit | 47fe18171569582d1af9401013c57045b59f3774 (patch) | |
| tree | b3dbfa96c90e6a36ac74b1f0e4ef1b8705a46470 /src/assets/shaders/truetype | |
| parent | fdafae3cdcb03a8b7fa736039556bcc465a34959 (diff) | |
Fix font rendering
Diffstat (limited to 'src/assets/shaders/truetype')
| -rw-r--r-- | src/assets/shaders/truetype/frag.glsl | 17 | ||||
| -rw-r--r-- | src/assets/shaders/truetype/vert.glsl | 27 |
2 files changed, 14 insertions, 30 deletions
diff --git a/src/assets/shaders/truetype/frag.glsl b/src/assets/shaders/truetype/frag.glsl index b0e25bf..3f62e01 100644 --- a/src/assets/shaders/truetype/frag.glsl +++ b/src/assets/shaders/truetype/frag.glsl @@ -2,22 +2,15 @@ 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; +in vec3 vertex_color; 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); + float val = texture(texture_data, vertex_texcoord).r; + if (val == 0.0) discard; + vec4 texel = vec4(vertex_color, val); + frag_color = texel; } diff --git a/src/assets/shaders/truetype/vert.glsl b/src/assets/shaders/truetype/vert.glsl index 4005d75..192d4b0 100644 --- a/src/assets/shaders/truetype/vert.glsl +++ b/src/assets/shaders/truetype/vert.glsl @@ -1,26 +1,17 @@ #version 300 es precision highp float; -uniform mat4 view; -uniform mat4 position; +in vec2 vertex; +in vec2 texcoord; +in vec3 color; + +uniform mat4 transform; out vec2 vertex_texcoord; +out vec3 vertex_color; 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; + vertex_texcoord = texcoord; + vertex_color = color; + gl_Position = transform * vec4(vertex, 0.0, 1.0); } |
