std::vector<GlyphQuad> FontAtlas::process(const std::string &text, float *width, float *height) const { ASSERT(generated, "Trying to process text with font atlas that is not generated"); std::vector<GlyphQuad> quads; float x = 0.0f, y = fontSize; for (char c : text) { int index = charIndex(c, glyphCategory); if (index < 0) { continue; } stbtt_aligned_quad q; stbtt_GetPackedQuad(packData->charData.data(), textureWidth, textureHeight, index, &x, &y, &q, 0); quads.push_back({ q.x0, q.y0, q.s0, q.t0, q.x1, q.y1, q.s1, q.t1 }); } if (width) { *width = x; } if (height) { *height = y; } return quads; }
void print(float x, float y, int font, char *text) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, font_tex); glBegin(GL_QUADS); while (*text) { stbtt_aligned_quad q; stbtt_GetPackedQuad(chardata[font], BITMAP_W, BITMAP_H, *text++, &x, &y, &q, font ? 0 : integer_align); drawBoxTC(q.x0,q.y0,q.x1,q.y1, q.s0,q.t0,q.s1,q.t1); } glEnd(); }