summaryrefslogtreecommitdiff
path: root/src/systems/text.h
blob: 4fac0b8316685167ef38cd2c856c3ebe9f9268dc (plain)
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
50
51
52
53
54
/**
 * @brief
 */
#pragma once

#include <stb_truetype.h>

#include "cleanroom/types.h"
#include "darray.h"
#include "defines.h"
#include "render_types.h"
#include "ral.h"

struct core;

/** @brief internal font struct */
typedef struct font {
  const char *name;
  stbtt_fontinfo stbtt_font;
  stbtt_bakedchar c_data[96];
  texture_handle bitmap_tex;
} font;

typedef struct draw_text_packet {
  char *contents;
  f32 x;
  f32 y;
} draw_text_packet;

KITC_DECL_TYPED_ARRAY(draw_text_packet)

typedef struct text_system_state {
  font default_font;
  shader_handle glyph_shader;
  u32 glyph_vbo;
  u32 glyph_vao;
  draw_text_packet_darray *draw_cmd_buf;
  // TODO: fonts array or hashtable
} text_system_state;

void text_system_render(text_system_state *text);

// --- Lifecycle functions
bool text_system_init(text_system_state *text);
void text_system_shutdown(text_system_state *text);

// --- Drawing

/**
 * @brief immediate mode draw text.
 * @note immediately emits draw calls causing a shader program switch if you weren't previously
         drawing text in the current frame.
*/
void draw_text(struct core *core, f32 x, f32 y, char *contents);