🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

BMFont: Different results with forcing zero offsets

Started by
1 comment, last by WitchLord 6 years, 9 months ago

Hello,

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?

orbitron-bold.otf

SIL Open Font License.txt

variable_offset.bmfc

variable_offset.fnt

variable_offset_0.png

variable_offset_render.png

zero_offset.bmfc

zero_offset.fnt

zero_offset_0.png

zero_offset_render.png

Advertisement

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 ) 
        return;

    int page = -1;
    render->Begin(RENDER_QUAD_LIST);

    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 )
        {
            render->End();
            page = ch->page;
            render->GetGraphics()->SetTexture(pages
);
            render->Begin(RENDER_QUAD_LIST);
        }

        render->VtxColor(color);
        render->VtxData(ch->chnl);
        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));
    }

    render->End();
}

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

 

Regards,
Andreas

 

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement