Added glyph rendering using stb_truetype

This commit is contained in:
2026-03-22 12:42:24 +05:45
parent 9af832adf6
commit 9294a1699f
4 changed files with 405 additions and 6 deletions
+52
View File
@@ -0,0 +1,52 @@
#version 450 core
#extension GL_ARB_texture_rectangle: enable
layout(location=1) uniform uint coverage_adjustment;
layout(location=2) uniform uint front_index; //gap buffer front
layout(binding = 0) uniform sampler2DRect glyph_atlas;
in vec2 tex_coords;
in flat vec4 color;
in flat float subpixel_shift;
in flat uint index_out;
layout(location = 0, index = 0) out vec4 fragment_color;
layout(location = 0, index = 1) out vec4 blend_weights;
void main (){
vec3 current = texelFetch(glyph_atlas, ivec2(tex_coords) + ivec2( 0, 0)).rgb;
vec3 previous = texelFetch(glyph_atlas, ivec2(tex_coords) + ivec2(-1, 0)).rgb;
float r = current.r, g = current.g, b = current.b;
if (subpixel_shift <= 1.0/3.0) {
float z = 3.0 * subpixel_shift;
r = mix(current.r, previous.b, z);
g = mix(current.g, current.r, z);
b = mix(current.b, current.g, z);
} else if (subpixel_shift <= 2.0/3.0) {
float z = 3.0 * subpixel_shift - 1.0;
r = mix(previous.b, previous.g, z);
g = mix(current.r, previous.b, z);
b = mix(current.g, current.r, z);
} else if (subpixel_shift < 1.0) {
float z = 3.0 * subpixel_shift - 2.0;
r = mix(previous.g, previous.r, z);
g = mix(previous.b, previous.g, z);
b = mix(current.r, previous.b, z);
}
vec3 pixel_coverages = vec3(r, g, b);
if(coverage_adjustment >= 0){
pixel_coverages = min(pixel_coverages * (1 + coverage_adjustment), 1);
}else{
pixel_coverages = max((1 - (1 - pixel_coverages) * (1 + -coverage_adjustment)), 0);
}
fragment_color = color * vec4(pixel_coverages, 1);
blend_weights = vec4(color.a * pixel_coverages, color.a);
}
+45
View File
@@ -0,0 +1,45 @@
#version 450 core
#extension GL_ARB_texture_rectangle: enable
layout(location=0) uniform vec2 half_viewport_size;
//layout(location=0) in uvec2 ltrb_index;
layout(location=0) in vec4 rect_ltrb;
layout(location=1) in vec4 rect_tex_ltrb;
layout(location=2) in vec4 rect_color;
//layout(location=4) in uint index;
layout(location=3) in float rect_subpixel_shift;
flat out vec2 tex_coords;
flat out vec4 color;
flat out float subpixel_shift;
flat out uint index_out;
void main(){
uvec2[6] rect_vertices = {
{0, 1}, //left top
{0, 3}, //left buttom
{2, 1}, //right top
{0, 3}, //Left buttom
{2, 3}, //right bottom
{2, 1}, //right top
};
//Convert color to pre-multipled alpha
uvec2 indexx = rect_vertices[gl_VertexID];
color = vec4(rect_color.rgb * rect_color.a, rect_color.a);
vec2 pos = vec2( rect_ltrb[indexx.x], rect_ltrb[indexx.y]);
tex_coords = vec2(rect_tex_ltrb[indexx.x], rect_tex_ltrb[indexx.y]);
subpixel_shift = rect_subpixel_shift;
//index_out = index;
vec2 axes_flip = vec2(1, -1); // to flip y axis from bottom up
vec2 pos_in_ndc = (pos / half_viewport_size - 1.0) * axes_flip;
gl_Position = vec4(pos_in_ndc, 0, 1);
}