-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathfree_glyph.h
More file actions
49 lines (34 loc) · 1.31 KB
/
free_glyph.h
File metadata and controls
49 lines (34 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef FREE_GLYPH_H_
#define FREE_GLYPH_H_
#include <stdlib.h>
#include "./la.h"
#define GLEW_STATIC
#include <GL/glew.h>
#define GL_GLEXT_PROTOTYPES
#include <SDL3/SDL_opengl.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include "simple_renderer.h"
#define FREE_GLYPH_FONT_SIZE 64
// https://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_02
typedef struct {
float ax; // advance.x
float ay; // advance.y
float bw; // bitmap.width;
float bh; // bitmap.rows;
float bl; // bitmap_left;
float bt; // bitmap_top;
float tx; // x offset of glyph in texture coordinates
} Glyph_Metric;
#define GLYPH_METRICS_CAPACITY 128
typedef struct {
FT_UInt atlas_width;
FT_UInt atlas_height;
GLuint glyphs_texture;
Glyph_Metric metrics[GLYPH_METRICS_CAPACITY];
} Free_Glyph_Atlas;
void free_glyph_atlas_init(Free_Glyph_Atlas *atlas, FT_Face face);
float free_glyph_atlas_cursor_pos(const Free_Glyph_Atlas *atlas, const char *text, size_t text_size, Vec2f pos, size_t col);
void free_glyph_atlas_measure_line_sized(Free_Glyph_Atlas *atlas, const char *text, size_t text_size, Vec2f *pos);
void free_glyph_atlas_render_line_sized(Free_Glyph_Atlas *atlas, Simple_Renderer *sr, const char *text, size_t text_size, Vec2f *pos, Vec4f color);
#endif // FREE_GLYPH_H_