diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-11 09:55:47 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-11 09:55:47 +0100 |
| commit | 9f6a7d71b179b72a12790a9d363789240003e20a (patch) | |
| tree | e5dd7193cf60421ce71964ada611613189bb3fdc /src | |
| parent | 228173ca185d4da22dce3318e07bc6ac65dfe32a (diff) | |
integrate freetype and load it
Diffstat (limited to 'src')
| -rw-r--r-- | src/text.cc | 11 | ||||
| -rw-r--r-- | src/text.h | 14 | ||||
| -rw-r--r-- | src/wayclock.cc | 26 |
3 files changed, 45 insertions, 6 deletions
diff --git a/src/text.cc b/src/text.cc new file mode 100644 index 0000000..cf5345d --- /dev/null +++ b/src/text.cc @@ -0,0 +1,11 @@ +#include "text.h" + +enum font_context_error_e wayc_font_context_init(struct font_context_s* ctx) { + FT_Error err = FT_Init_FreeType(&ctx->library); + if (err) return FONT_CONTEXT_ERROR_LIBRARY; + return FONT_CONTEXT_ERROR_NONE; +} + +void wayc_font_context_deinit(struct font_context_s* ctx) { + FT_Done_FreeType(ctx->library); +}
\ No newline at end of file @@ -1,7 +1,15 @@ #pragma once -#include "utils.h" -#include "vec.h" +#include "freetype/freetype.h" +enum font_context_error_e { + FONT_CONTEXT_ERROR_NONE, + FONT_CONTEXT_ERROR_LIBRARY, +}; -struct font_s {}; +struct font_context_s { + FT_Library library; +}; + +enum font_context_error_e wayc_font_context_init(struct font_context_s* ctx); +void wayc_font_context_deinit(struct font_context_s* ctx); diff --git a/src/wayclock.cc b/src/wayclock.cc index d381641..3911ca0 100644 --- a/src/wayclock.cc +++ b/src/wayclock.cc @@ -3,6 +3,7 @@ #include "events.h" #include "glad.h" #include "graphics.h" +#include "text.h" #include "utils.h" #include "window.h" @@ -10,6 +11,11 @@ #define WAYC_APP_WIDTH 1280 #define WAYC_APP_HEIGHT 1080 +struct app_s { + struct renderer_s* renderer; + struct font_context_s* fctx; +}; + void wayc_frame(struct renderer_s* renderer, struct window_s* window, struct eventloop_s* loop) { wayc_notnull(window); @@ -26,7 +32,8 @@ void wayc_handle(u8* user, struct eventloop_s* loop, struct event_s* event) { wayc_notnull(loop); wayc_notnull(event); - struct renderer_s* renderer = (struct renderer_s*)user; + struct app_s* app = (struct app_s*)user; + struct renderer_s* renderer = app->renderer; struct window_s* window = event->window; union event_data_u data = event->data; @@ -48,9 +55,15 @@ void wayc_handle(u8* user, struct eventloop_s* loop, struct event_s* event) { } int main() { + struct font_context_s fctx; + if (wayc_font_context_init(&fctx) != FONT_CONTEXT_ERROR_NONE) + wayc_panic("Failed to initialize font context"); + struct eventloop_s loop; - if (wayc_eventloop_init(&loop, wayc_handle) != EVENTLOOP_ERROR_NONE) + if (wayc_eventloop_init(&loop, wayc_handle) != EVENTLOOP_ERROR_NONE) { + wayc_font_context_deinit(&fctx); wayc_panic("Failed to initialize event loop"); + } struct graphics_s graphics; if (wayc_graphics_init(&graphics, &loop.state) != GRAPHICS_ERROR_NONE) @@ -78,8 +91,13 @@ int main() { wayc_renderer_use(&renderer); wayc_window_redraw(&window, &loop); + struct app_s app = { + &renderer, + &fctx, + }; + while (wayc_eventloop_running(&loop)) { - wayc_eventloop_update(&loop, (u8*)&renderer); + wayc_eventloop_update(&loop, (u8*)&app); wayc_window_redraw(&window, &loop); } @@ -87,5 +105,7 @@ int main() { wayc_window_deinit(&window); wayc_graphics_deinit(&graphics); wayc_eventloop_deinit(&loop); + + wayc_font_context_deinit(&fctx); return 0; }
\ No newline at end of file |
