49 lines
985 B
C++
49 lines
985 B
C++
#pragma once
|
|
#include "texture.h"
|
|
#include "util.h"
|
|
#include <stb/stb_truetype.h>
|
|
|
|
enum class kFont : uint16_t
|
|
{
|
|
Arial_11 = const_hash("arial-11"),
|
|
Arial_30 = const_hash("arial-30"),
|
|
};
|
|
|
|
class Font
|
|
{
|
|
public:
|
|
const int w = 512;
|
|
const int h = 512;
|
|
const int num_chars = 96;
|
|
const int start_char = 32;
|
|
stbtt_fontinfo font;
|
|
Texture2D font_tex;
|
|
std::vector<stbtt_bakedchar> chars;
|
|
|
|
bool load(const char* ttf, int sz);
|
|
};
|
|
|
|
class FontManager
|
|
{
|
|
public:
|
|
static std::map<kFont, Font> m_fonts;
|
|
static Sampler m_sampler;
|
|
static void init();
|
|
static bool load(kFont id, const char* ttf, int sz);
|
|
static const Font& get(kFont id);
|
|
static void invalidate() { m_fonts.clear(); }
|
|
};
|
|
|
|
class TextMesh
|
|
{
|
|
public:
|
|
GLuint font_array = 0;
|
|
int font_array_count = 0;
|
|
GLuint font_buffers[2] = {0, 0};
|
|
kFont font_id;
|
|
glm::vec2 bb = { 0, 0 };
|
|
bool create();
|
|
void update(kFont id, const char* text);
|
|
void draw();
|
|
};
|