17 #define MAP_HEIGHT 512
19 #define MAP_NUM_CHARS 100
26 other.begin = other.texture = -1;
28 other.charInfo =
nullptr;
103 std::ifstream file(f, std::ios::binary);
109 file.seekg(0, std::ios::end);
110 auto size = file.tellg();
121 if (!file.read(reinterpret_cast<char*>(
fontData), size)) {
148 float x = 0.0f, y = 0.0f;
150 for (
int i = 0; i < s.length(); i++) {
151 if ((s[i] < 0x20) || (s[i] == 0x7F)) {
161 glm::vec4 color, std::string s) {
168 for (
int i = 0; i < s.length(); i++) {
169 if ((s[i] < 0x20) || (s[i] == 0x7F)) {
183 glm::vec4 color,
unsigned int maxWidth, std::string s) {
188 glm::vec4 color,
unsigned int maxWidth, std::string s,
190 std::vector<glm::vec2> vertices;
191 std::vector<glm::vec2> uvs;
194 for (
int i = 0; i < s.length(); i++) {
195 if ((s[i] < 0x20) || (s[i] == 0x7F)) {
200 int tex =
getQuad(s[i], &xpos, &ypos, &quad);
202 if (drawWrapped && (xpos > (x + maxWidth))) {
210 if ((texture != tex) && (texture != -1)) {
220 float xmin = quad.
x0;
221 float xmax = quad.
x0 + ((quad.
x1 - quad.
x0) * scale);
222 float ymin = quad.
y1;
223 float ymax = quad.
y1 + ((quad.
y0 - quad.
y1) * scale);
225 vertices.emplace_back(xmin, ymin);
226 vertices.emplace_back(xmin, ymax);
227 vertices.emplace_back(xmax, ymax);
228 vertices.emplace_back(xmax, ymin);
229 vertices.emplace_back(xmin, ymin);
230 vertices.emplace_back(xmax, ymax);
232 uvs.emplace_back(quad.
s0, quad.
t1);
233 uvs.emplace_back(quad.
s0, quad.
t0);
234 uvs.emplace_back(quad.
s1, quad.
t0);
235 uvs.emplace_back(quad.
s1, quad.
t1);
236 uvs.emplace_back(quad.
s0, quad.
t1);
237 uvs.emplace_back(quad.
s1, quad.
t0);
246 for (
int i = 0; i <
maps.size(); i++) {
247 if (
maps.at(i).contains(c)) {
256 Log::get(
LOG_INFO) <<
"Unmapped character '" << char(c) <<
"', new map from " << begin <<
" to "
276 maps.at(map).getQuad(c, xpos, ypos, quad);
277 return maps.at(map).getTexture();
void bufferData(int elem, int size, void *data)
unsigned char * grayscale2rgba(unsigned char *image, unsigned int w, unsigned int h)
static int initialize(std::string f)
STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, unsigned char *fontdata, int font_index, float font_size, int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range)
static unsigned int widthText(float scale, std::string s)
static LogLevel & get(int level)
STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context)
TrueType Font Implementation.
static std::vector< FontMapTTF > maps
static unsigned char * fontData
static void drawTextWrapped(unsigned int x, unsigned int y, float scale, glm::vec4 color, unsigned int maxWidth, std::string s)
static ShaderBuffer uvBuffer
static unsigned int heightText(float scale, unsigned int maxWidth, std::string s)
static void drawGL(ShaderBuffer &vertices, ShaderBuffer &uvs, glm::vec4 color, unsigned int texture, TextureStorage store=TextureStorage::SYSTEM, unsigned int mode=GL_TRIANGLES, ShaderTexture *target=nullptr, Shader &shader=textShader)
int initialize(unsigned char *fontData, int firstChar)
void getQuad(int c, float *xpos, float *ypos, stbtt_aligned_quad *quad)
STBTT_DEF void stbtt_GetPackedQuad(stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer)
STBTT_DEF void stbtt_PackEnd(stbtt_pack_context *spc)
static ShaderBuffer vertexBuffer
stbtt_packedchar * charInfo
static void drawTextInternal(unsigned int x, unsigned int y, float scale, glm::vec4 color, unsigned int maxWidth, std::string s, bool drawWrapped)
static int charIsMapped(int c)
STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample)
static void drawText(unsigned int x, unsigned int y, float scale, glm::vec4 color, std::string s)
static int loadBufferSlot(unsigned char *image=nullptr, unsigned int width=256, unsigned int height=256, ColorMode mode=ColorMode::RGBA, unsigned int bpp=32, TextureStorage s=TextureStorage::GAME, int slot=-1, bool filter=true)
Loads Buffer as texture.
static int getQuad(int c, float *xpos, float *ypos, stbtt_aligned_quad *quad)