# 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.

## Recommended Posts

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;

}

Has somebody noticed a similar behaviour?

orbitron-bold.otf

variable_offset.bmfc

variable_offset.fnt

zero_offset.bmfc

zero_offset.fnt

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

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

);
}

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 )
}

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

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 17
• 12
• 9
• 9
• 25