22 vert_tex2d(
float x,
float y,
float u,
float v)
23 : x(x), y(y), u(u), v(v) { }
36 glDeleteTextures(1, &font_tex);
40 if (FT_New_Face(library, path.c_str(), font_index, &face))
42 cout <<
"GlVisFont::LoadFont(): Cannot open font file: " << path << endl;
45 face_has_kerning = FT_HAS_KERNING(face);
48 const bool use_fixed_ppi_h =
true;
51 double ratio = double(ppi_w)/ppi_h;
53 ppi_w = ratio*ppi_h + 0.5;
55 cout <<
"Fonts use fixed ppi: " << ppi_w <<
" x " << ppi_h << endl;
58 if (FT_Set_Char_Size(face, 0, font_size*
font_scale, ppi_w, ppi_h))
60 cout <<
"GlVisFont::LoadFont(): Cannot set font height: " << font_size
66 cout <<
"Loaded font: " << path <<
", index: " << font_index
67 <<
", height: " << font_size << endl;
72 for (
int c = 32; c < 128; c++)
74 if (FT_Load_Char(face, c, FT_LOAD_RENDER))
76 cout <<
"GlVisFont::LoadFont(): Cannot load glyph: " << (char) c << endl;
79 w += face->glyph->bitmap.width + 2;
80 if (h <
size_t(face->glyph->bitmap.rows))
82 h = face->glyph->bitmap.rows;
89 cout <<
"GlVisFont::LoadFont(): font texture dimensions are ("
90 << tex_w <<
", " << tex_h <<
")" << endl;
93 glGenTextures(1, &font_tex);
95 glActiveTexture(GL_TEXTURE0 + 1);
96 glBindTexture(GL_TEXTURE_2D, font_tex);
97 std::vector<uint8_t> zeros(tex_w * tex_h, 0);
98 GLenum alpha_internal_fmt = alpha_channel == GL_RED ? GL_R8 : GL_ALPHA;
99 glTexImage2D(GL_TEXTURE_2D, 0, alpha_internal_fmt, tex_w, tex_h, 0,
101 GL_UNSIGNED_BYTE, zeros.data());
103 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
104 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
106 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
110 for (
int c = 32; c < 128; c++)
112 if (FT_Load_Char(face, c, FT_LOAD_RENDER))
114 cout <<
"GlVisFont::LoadFont(): Cannot load glyph: " << (char) c << endl;
117 FT_GlyphSlot glyph_slot = face->glyph;
118 glTexSubImage2D(GL_TEXTURE_2D,
121 glyph_slot->bitmap.width,
122 glyph_slot->bitmap.rows,
125 glyph_slot->bitmap.buffer);
132 (unsigned)(glyph_slot->bitmap.width + 2),
133 (unsigned)(glyph_slot->bitmap.rows + 2),
134 glyph_slot->bitmap_left,
135 glyph_slot->bitmap_top,
136 glyph_slot->advance.x / 64.f,
137 glyph_slot->advance.y / 64.f,
140 x += glyph_slot->bitmap.width + 2;
144 glActiveTexture(GL_TEXTURE0);
150 float pen_x = 0.f, pen_y = 0.f;
152 int min_x = INT_MAX, max_x = INT_MIN;
153 int min_y = INT_MAX, max_y = INT_MIN;
157 if (!g.
w || !g.
h) {
continue; }
162 min_x = std::min(min_x, (
int)floorf(pen_x));
163 max_x = std::max(max_x, (
int)ceilf (pen_x + g.
adv_x));
164 min_y = std::min(min_y, (
int)floorf(pen_y + g.
bear_y - (g.
h - 2)));
165 max_y = std::max(max_y, (
int)ceilf (pen_y + g.
bear_y));
float GetKerning(char cprev, char c)
bool isHighDpi() const
This property is set by createWindow().
SdlWindow * GetAppWindow()
void getObjectSize(const std::string &text, int &w, int &h)
Get the width and height of the bounding box containing the rendered text.
const glyph & GetTexChar(char c) const
bool LoadFont(const std::string &path, int font_index, int font_size)
void getDpi(int &wdpi, int &hdpi)