aboutsummaryrefslogtreecommitdiff
path: root/include/mgl/graphics/font.h
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-15 08:20:13 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-15 08:20:13 +0100
commita3c6774f211ee765f910df76837548bdadd4e959 (patch)
tree499b29166c04fa62cb946c7d395f8a5299c78fbf /include/mgl/graphics/font.h
parentc4f84e1969f4c856a5bf0352e99fcb73a4cf56cf (diff)
Add dynamic font atlas creation (not finished)
Diffstat (limited to 'include/mgl/graphics/font.h')
-rw-r--r--include/mgl/graphics/font.h34
1 files changed, 21 insertions, 13 deletions
diff --git a/include/mgl/graphics/font.h b/include/mgl/graphics/font.h
index c4904ff..adcc8a7 100644
--- a/include/mgl/graphics/font.h
+++ b/include/mgl/graphics/font.h
@@ -1,37 +1,45 @@
#ifndef MGL_FONT_H
#define MGL_FONT_H
-#include "../system/vec.h"
+#include "../system/fileutils.h"
+#include "font_char_map.h"
#include "texture.h"
#include <stdint.h>
+typedef struct mgl_memory_mapped_file mgl_memory_mapped_file;
typedef struct mgl_font mgl_font;
-typedef struct {
- mgl_vec2f position;
- mgl_vec2f size;
- mgl_vec2f texture_position;
- mgl_vec2f texture_size;
- float advance;
-} mgl_font_glyph;
+typedef enum {
+ MGL_ATLAS_SECTION_INITIAL,
+ MGL_ATLAS_SECTION_RIGHT,
+ MGL_ATLAS_SECTION_BOTTOM
+} mgl_font_atlas_render_section;
typedef struct {
- unsigned char *atlas;
int width;
int height;
+ int prev_width;
+ int prev_height;
+ mgl_vec2i pointer_position;
+ mgl_font_atlas_render_section render_section;
} mgl_font_atlas;
struct mgl_font {
mgl_texture texture;
mgl_font_atlas font_atlas;
unsigned int character_size;
- void *packed_chars;
- uint32_t num_packed_chars;
+ mgl_font_char_map char_map;
+ int current_line_max_height;
+ void *font_info;
};
-int mgl_font_load_from_file(mgl_font *self, const char *filepath, unsigned int character_size);
+int mgl_font_load_from_file(mgl_font *self, const mgl_memory_mapped_file *mapped_file, unsigned int character_size);
void mgl_font_unload(mgl_font *self);
-int mgl_font_get_glyph(const mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph);
+/* Note: loads the glyph if it hasn't been loaded yet */
+int mgl_font_get_glyph(mgl_font *self, uint32_t codepoint, mgl_font_glyph *glyph);
+
+/* Returns the kerning */
+int mgl_font_get_kerning(const mgl_font *self, uint32_t prev_codepoint, uint32_t codepoint);
#endif /* MGL_FONT_H */