summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-12 17:54:15 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-12 17:54:15 +0100
commit6c5bfa228502bd06989c1892d71c61add419a0ea (patch)
treed2a3fd0c76c60957a1facff0996f475e88e83443 /src
parent654cd13559cc8325f69eb38612c454b1db4bfca6 (diff)
oh je
Diffstat (limited to 'src')
-rw-r--r--src/geometry.h4
-rw-r--r--src/text.cc47
-rw-r--r--src/text.h25
3 files changed, 70 insertions, 6 deletions
diff --git a/src/geometry.h b/src/geometry.h
index 19698c6..6c3e36a 100644
--- a/src/geometry.h
+++ b/src/geometry.h
@@ -10,8 +10,8 @@ struct quad_s {
u32 indices[WAYC_QUAD_NINDICES];
};
-static inline void wayc_quad_init(quad_s* quad, f32 left, f32 top, f32 right,
- f32 bottom) {
+static inline void wayc_quad_init(struct quad_s* quad, f32 left, f32 top,
+ f32 right, f32 bottom) {
wayc_notnull(quad);
/*
diff --git a/src/text.cc b/src/text.cc
new file mode 100644
index 0000000..7131d44
--- /dev/null
+++ b/src/text.cc
@@ -0,0 +1,47 @@
+#include "text.h"
+
+#include "freetype/freetype.h"
+#include "freetype/fttypes.h"
+#include "graphics.h"
+#include "text_shader.h"
+#include "utils.h"
+
+static void font_context_sampler_desc(struct sg_sampler_desc* desc) {
+ wayc_notnull(desc);
+
+ desc->min_filter = SG_FILTER_LINEAR;
+ desc->mag_filter = SG_FILTER_LINEAR;
+ desc->wrap_u = SG_WRAP_CLAMP_TO_EDGE;
+ desc->wrap_v = SG_WRAP_CLAMP_TO_EDGE;
+}
+
+static void font_context_pipeline_desc(struct sg_pipeline_desc* desc) {
+ wayc_notnull(desc);
+
+ struct sg_shader_desc shader_desc = *text_shader_desc(sg_query_backend());
+ sg_shader shader = sg_make_shader(&shader_desc);
+
+ desc->shader = shader;
+}
+
+enum font_context_error_e font_context_init(struct font_context_s* context) {
+ wayc_notnull(context);
+
+ FT_Library ft;
+ FT_Error fterr = FT_Init_FreeType(&ft);
+ if (fterr) return FONT_CONTEXT_ERROR_LOAD_LIBRARY;
+
+ struct sg_sampler_desc sampler_desc = {};
+ font_context_sampler_desc(&sampler_desc);
+
+ struct sg_pipeline_desc pipeline_desc = {};
+ font_context_pipeline_desc(&pipeline_desc);
+
+ context->ft = ft;
+ context->sampler = sg_make_sampler(&sampler_desc);
+ context->pipeline = sg_make_pipeline(&pipeline_desc);
+
+ return FONT_CONTEXT_ERROR_NONE;
+}
+
+void font_context_deinit(struct font_context_s* context); \ No newline at end of file
diff --git a/src/text.h b/src/text.h
index 6eb7df1..efaad8f 100644
--- a/src/text.h
+++ b/src/text.h
@@ -1,11 +1,28 @@
#pragma once
#include "freetype/freetype.h"
+#include "sokol_gfx.h"
+#include "utils.h"
-struct face_ctx_s {
- FT_Library library;
+enum font_context_error_e : u8 {
+ FONT_CONTEXT_ERROR_NONE = 0,
+ FONT_CONTEXT_ERROR_LOAD_LIBRARY,
};
-struct face_s {
+struct font_context_s {
+ FT_Library ft;
+ struct sg_pipeline pipeline;
+ struct sg_sampler sampler;
+};
+
+enum font_context_error_e font_context_init(struct font_context_s* context);
+void font_context_deinit(struct font_context_s* context);
+
+struct font_s {
FT_Face face;
-}; \ No newline at end of file
+ u8* source;
+
+ u8* staging;
+ bool staging_dirty;
+ struct sg_image atlas;
+};