Open achalpandeyy opened 8 months ago
Yes, you are correct. (The documentation was probably incorrectly derived from stbtt_GetFontBoundingBox
.)
Thank you, Sean, for the prompt response and all this excellent work.
I assume that this will get bundled with other doc fixes, so closing the issue now.
Better to leave the issue open to make sure it gets fixed.
Specifically, under the "Displaying a character" heading , it says:
If I use
stbtt_GetCodepointBitmapBox
to compute the bounding box of the character, the values I get back i.e.x0, x1, y0, y1
appear to be already scaled by theSF
factor, so there should be no need for the multiplication withSF
. I think this for the following two reasons:x1-x0
andy1-y0
gives the bitmap's width and height respectively as reported by thestbtt_GetCodepointBitmap
function which already takes in theSF
factor and also reports different bitmap dimensions for differentSF
values.SF
value twice. See the code below for my usage:float SF = stbtt_ScaleForPixelHeight(&font_info, 128.f);
int x0, x1, y0, y1; stbtt_GetCodepointBitmapBox(&font_info, codepoint, SF, SF, &x0, &y0, &x1, &y1);
int width, height, x_offset, y_offset; unsigned char *bitmap_data = stbtt_GetCodepointBitmap(&font_info, 0, SF, codepoint, &width, &height, &x_offset, &y_offset);
assert(width == (x1-x0)); assert(height == (y1-y0));
float current_point_x = 30.f + SFx0; float current_point_y = 40.f + SFy0;
DrawBitmap(current_point_x, current_point_y, width, height, bitmap_data);