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 | |
| parent | 70925ed8178ceec3fa14e7f2abbc7f0054f1d190 (diff) | |
idk
| -rw-r--r-- | src/text.cc | 54 | ||||
| -rw-r--r-- | src/wayclock.cc | 6 |
2 files changed, 32 insertions, 28 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); diff --git a/src/wayclock.cc b/src/wayclock.cc index bd8491e..a221174 100644 --- a/src/wayclock.cc +++ b/src/wayclock.cc @@ -1,5 +1,6 @@ +#include "cglm/types.h" #include "events.h" #include "graphics.h" #include "text.h" @@ -17,6 +18,7 @@ struct app_s { struct renderer_s* renderer; + struct font_s* font; }; void wayc_frame(struct app_s* app, struct window_s* window, @@ -26,6 +28,8 @@ void wayc_frame(struct app_s* app, struct window_s* window, wayc_notnull(app); struct renderer_s* renderer = app->renderer; + struct font_s* font = app->font; + (void)font; wayc_renderer_begin(renderer); wayc_renderer_end(renderer); @@ -101,7 +105,7 @@ int main() { wayc_panic("Failed to initialize font"); wayc_defer(wayc_font_deinit(&font)); - struct app_s app = {&renderer}; + struct app_s app = {&renderer, &font}; while (wayc_eventloop_running(&loop)) { wayc_eventloop_update(&loop, (u8*)&app); |
