Im using the stb_truetype.h for rendering text, and more specifically this API
1 2 3 4 5 6 7 | // Improved 3D API (more shippable): // #include "stb_rect_pack.h" -- optional, but you really want it // stbtt_PackBegin() // stbtt_PackSetOversampling() -- for improved quality on small fonts // stbtt_PackFontRanges() -- pack and renders // stbtt_PackEnd() // stbtt_GetPackedQuad() |
However, if i render a sentence like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | char line[50] = {}; strcpy(line, "get Outt'a heregj!"); for(i32 i = 0; i < strlen(line); i++) { adv = xp / (float)win32.win_w; stbtt_GetPackedQuad(packed_char, 1024, 1024, line[i] - ' ', &xp, &yp, &glyph_quad, 0); t_pos_x = glyph_quad.s0; t_pos_y = 1.0f - glyph_quad.t1; t_sz_x = glyph_quad.s1 - glyph_quad.s0; t_sz_y = (1.0f - glyph_quad.t0) - (1.0f - glyph_quad.t1); c_w = (glyph_quad.x1 - glyph_quad.x0) / (float)win32.win_w; c_h = (glyph_quad.y1 - glyph_quad.y0) / (float)win32.win_h; CreateQuad(vBuff, 5 + i, v2f(-0.5f + adv, 0.3f), v2f(c_w, c_h), v4f(1.0f, 1.0f, 1.0f, 1.0f), v2f(t_pos_x, t_pos_y), v2f(t_sz_x, t_sz_y)); } |
the xp advances the cursor (to the right) to where the next character in the sentence should be, however the yp doesn't get modified even if the character beeing sent to stbtt_GetPackedQuad() is a 'g' or 'j', so the 'g' or 'j' doesn't get rendered with respect to the baseline.
I went through the stbtt_GetPackedQuad() defintion, and at the end only the *xpos get's modified and not the *ypos.
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 | STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer) { float ipw = 1.0f / pw, iph = 1.0f / ph; const stbtt_packedchar *b = chardata + char_index; if (align_to_integer) { float x = (float) STBTT_ifloor((*xpos + b->xoff) + 0.5f); float y = (float) STBTT_ifloor((*ypos + b->yoff) + 0.5f); q->x0 = x; q->y0 = y; q->x1 = x + b->xoff2 - b->xoff; q->y1 = y + b->yoff2 - b->yoff; } else { q->x0 = *xpos + b->xoff; q->y0 = *ypos + b->yoff; q->x1 = *xpos + b->xoff2; q->y1 = *ypos + b->yoff2; } q->s0 = b->x0 * ipw; q->t0 = b->y0 * iph; q->s1 = b->x1 * ipw; q->t1 = b->y1 * iph; *xpos += b->xadvance; } |
Any thoughts on this?