Jump to content
  • Advertisement
Marc Klein

BMFont: Different results with forcing zero offsets

This topic is 776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


I'm using BMfont to create a Bitmap font for my text Rendering. I noticed some strange behaviour when I use the option "force Offsets to Zero".

If I use this option my rendering resultions looks ok, but without it, there is some missing space between some characters.

I attached the BMFont configuration files and font that I used.

In the rendering result with variable Offset you can see that there is missing space right next to the "r" letter.

To get the source and destination of my render rectangles I basically to following:

void getBakedQuad(const fontchar_t* f, int* x_cursor, int * y_cursor, SDL_Rect* src, SDL_Rect* dest) {

dest->x = *x_cursor + f->xoffset;
dest->y = *y
_cursor + f->yoffset;
dest->w = f->width;

dest->h = f->height;

src->x = f->x;
src->y = f->y;
src->w = f->width;
src->h = f->height;

*x_cursor += f->xadvance;


Has somebody noticed a similar behaviour?


SIL Open Font License.txt









Share this post

Link to post
Share on other sites

I see nothing wrong with the generated font files in either case. For this particular font there shouldn't be any difference between the two. When forcing the offsets to zero BMFont will embed the offsets within the quads themselves, and inspecting the font files I can see that this was done.

The difference you see might be a case of rounding errors when drawing the text. Either with the texture coordinates, or the placement of the quads on the screen.

For reference, here's the code I use to draw text with:

void CFont::InternalWrite(float x, float y, float z, const char *text, int count, float spacing)
    if( render->GetGraphics() == 0 ) 

    int page = -1;

    y += scale * float(base);

    for( int n = 0; n < count; )
        int charId = GetTextChar(text, n, &n);
        SCharDescr *ch = GetChar(charId);
        if( ch == 0 ) ch = &defChar;

        // Map the center of the texel to the corners
        // in order to get pixel perfect mapping
        float u = (float(ch->srcX)+0.5f) / scaleW;
        float v = (float(ch->srcY)+0.5f) / scaleH;
        float u2 = u + float(ch->srcW) / scaleW;
        float v2 = v + float(ch->srcH) / scaleH;

        float a = scale * float(ch->xAdv);
        float w = scale * float(ch->srcW);
        float h = scale * float(ch->srcH);
        float ox = scale * float(ch->xOff);
        float oy = scale * float(ch->yOff);

        if( ch->page != page )
            page = ch->page;


        render->VtxTexCoord(u, v);
        render->VtxPos(x+ox, y-oy, z);
        render->VtxTexCoord(u2, v);
        render->VtxPos(x+w+ox, y-oy, z);
        render->VtxTexCoord(u2, v2);
        render->VtxPos(x+w+ox, y-h-oy, z);
        render->VtxTexCoord(u, v2);
        render->VtxPos(x+ox, y-h-oy, z);

        x += a;
        if( charId == ' ' )
            x += spacing;

        if( n < count )
            x += AdjustForKerningPairs(charId, GetTextChar(text,n));


The complete code can be found here: http://svn.code.sf.net/p/actb/code/trunk/source/gfx/acgfx_font.cpp




Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!