diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-13 08:45:51 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-13 08:45:51 +0100 |
| commit | 6223e4356950268a2ca88a45a1de22bcae3e50fa (patch) | |
| tree | 2f9a905862193a4779df4e370acfcd5911f6959b /src/text.cc | |
| parent | 70925ed8178ceec3fa14e7f2abbc7f0054f1d190 (diff) | |
idk
Diffstat (limited to 'src/text.cc')
| -rw-r--r-- | src/text.cc | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/text.cc b/src/text.cc index a56033a..f438aed 100644 --- a/src/text.cc +++ b/src/text.cc @@ -61,11 +61,38 @@ static void font_context_pipeline_desc(struct sg_pipeline_desc* desc, desc->layout = vertex_layout; desc->shader = shader; + desc->index_type = SG_INDEXTYPE_UINT16; desc->colors[0] = color; desc->color_count = 1; } +static void wayc_text_quad(struct text_vertex_s* verts, u16* indices, u16 base, + const struct glyph_s* glyph, vec2 cursor) { + f32 x0 = WAYC_X(cursor) + WAYC_X(glyph->bearing); + f32 y0 = WAYC_Y(cursor) - WAYC_Y(glyph->bearing); + f32 x1 = x0 + WAYC_X(glyph->size); + f32 y1 = y0 + WAYC_Y(glyph->size); + + struct quad_s quad; + wayc_quad_init(&quad, x0, y0, x1, y1); + + vec2 uvs[WAYC_QUAD_NVERTS] = { + {WAYC_X(glyph->uv0), WAYC_Y(glyph->uv0)}, + {WAYC_X(glyph->uv1), WAYC_Y(glyph->uv0)}, + {WAYC_X(glyph->uv1), WAYC_Y(glyph->uv1)}, + {WAYC_X(glyph->uv0), WAYC_Y(glyph->uv1)}, + }; + + for (usize j = 0; j < WAYC_QUAD_NVERTS; j++) { + glm_vec2_copy(quad.vertices[j], verts[base + j].pos); + glm_vec2_copy(uvs[j], verts[base + j].uv); + } + + for (usize j = 0; j < WAYC_QUAD_NINDICES; j++) + indices[j] = (u16)(base + quad.indices[j]); +} + enum font_context_error_e wayc_font_context_init( struct font_context_s* context) { wayc_notnull(context); @@ -240,33 +267,6 @@ void wayc_font_deinit(struct font_s* font) { FT_Done_Face(font->face); } -static void wayc_text_quad(struct text_vertex_s* verts, u16* indices, - u16 base, const struct glyph_s* glyph, - vec2 cursor) { - f32 x0 = WAYC_X(cursor) + WAYC_X(glyph->bearing); - f32 y0 = WAYC_Y(cursor) - WAYC_Y(glyph->bearing); - f32 x1 = x0 + WAYC_X(glyph->size); - f32 y1 = y0 + WAYC_Y(glyph->size); - - struct quad_s quad; - wayc_quad_init(&quad, x0, y0, x1, y1); - - vec2 uvs[WAYC_QUAD_NVERTS] = { - {WAYC_X(glyph->uv0), WAYC_Y(glyph->uv0)}, - {WAYC_X(glyph->uv1), WAYC_Y(glyph->uv0)}, - {WAYC_X(glyph->uv1), WAYC_Y(glyph->uv1)}, - {WAYC_X(glyph->uv0), WAYC_Y(glyph->uv1)}, - }; - - for (usize j = 0; j < WAYC_QUAD_NVERTS; j++) { - glm_vec2_copy(quad.vertices[j], verts[base + j].pos); - glm_vec2_copy(uvs[j], verts[base + j].uv); - } - - for (usize j = 0; j < WAYC_QUAD_NINDICES; j++) - indices[j] = (u16)(base + quad.indices[j]); -} - bool wayc_text_mesh_init(struct text_mesh_s* mesh, const char* text, usize text_len, struct font_s* font) { wayc_notnull(mesh); |
