# Bitmap font spacing

## Recommended Posts

schragnasher    120
Im using the LMNOpc Font creation app. Iv got everything working except i cant get the text to line up next to each other when using the widths data. Iv verified the widths data loads correctly by checking it against the .ini output file so the data should be correct. It looks like this....Arial Font isnt spaced oddly like this. Also if i do not use the widths data and keep the spacing constant it works as intended. This looks right , if i add the grid to the image itl show each square like it should. Has anyone used these widths correctly that can help me out?

##### Share on other sites
szecs    2990
Maybe you position a glyph based on its own width, but you have to place it based on the width of the previous glyph.

That's just a wild guess, but I think it's something similar like that.

##### Share on other sites
schragnasher    120
The addition is happening after i render the current glyph.
So i render then add the current glyph width to the position.

I hate posting code cause i always think im likely doing stupid things, but anyway here is the text draw function. Its hacky and probly terrible but thats not the point right now. lol

void cGraphics::DrawText(std::string Text,cSPointer<cFont> Font){    glEnableClientState(GL_VERTEX_ARRAY);    glEnableClientState(GL_TEXTURE_COORD_ARRAY);    glEnable(GL_TEXTURE_2D);    glBindTexture(GL_TEXTURE_2D,Font->GetTexture());    GLfloat TexWidth = Font->GetTextureWidth();    GLfloat TexHeight = Font->GetTextureHeight();    std::vector<GLfloat> Vert;    std::vector<GLfloat> Tex;    int FW = Font->GetTextureWidth()/16;    int FH = Font->GetTextureHeight()/16;    int w=0;    for(unsigned int x=0;x<Text.length();x++){        //add quad verts        Vert.push_back(w);Vert.push_back(0);        Vert.push_back((w)+FW);Vert.push_back(0);        Vert.push_back((w)+FW);Vert.push_back(FH);        Vert.push_back(w);Vert.push_back(FH);        //add texture coords        float v1=(Text[x]%16)*FW;        float v2=(Text[x]/16)*FH;        Tex.push_back(v1/TexWidth);Tex.push_back((v2+FH)/TexHeight);        Tex.push_back((v1+FW)/TexWidth);Tex.push_back((v2+FH)/TexHeight);        Tex.push_back((v1+FW)/TexWidth);Tex.push_back(v2/TexHeight);        Tex.push_back(v1/TexWidth);Tex.push_back(v2/TexHeight);        //move to next position        w+=Font->Widths[int(Text[x])];    }    glVertexPointer(2,GL_FLOAT,0,&Vert[0]);    glTexCoordPointer(2,GL_FLOAT,0,&Tex[0]);    glDrawArrays(GL_QUADS,0,Text.length()*4);    glDisable(GL_TEXTURE_2D);    glDisableClientState(GL_VERTEX_ARRAY);    glDisableClientState(GL_TEXTURE_COORD_ARRAY);}

##### Share on other sites
szecs    2990
Yup, I don't really understand the code, but it's not your fault.

EDIT: I understand the code, and it looks fine (the code is not the most optional: you draw the whole FW*FH quad, instead of drawing a quad, that fits tightly to the glyph, so you draw more pixels than necessary)

I can think of one thing: the glyphs aren't aligned left in the texture.
I mean: It's like this:
|    a|
|a    |
I think the image you posted shows that behavior. I hope it's clear, that I'm trying to say.
You can try it by drawing a colored Quad with the same coordinates under one glyph.

##### Share on other sites
schragnasher    120
Well that does seem to fix it, but i get a weird problem with "j" lol it seems the font creator might have an issue as the bottom of the "j" bleeds over into the glyph to the left of it. It can be fixed by changing my texture coordinate code, but thats kinda weird.

Anyhow, this looks much better and seems to be what the issue was. Thanks

EDIT: Yes exactly as you said :)

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account