Jump to content
  • Advertisement
Sign in to follow this  

Bitmap font spacing

This topic is 3018 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

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 this post

Link to post
Share on other sites
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 this post

Link to post
Share on other sites
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){


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

//add texture coords
float v1=(Text[x]%16)*FW;
float v2=(Text[x]/16)*FH;


//move to next position


Share this post

Link to post
Share on other sites
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|
instead of this:
|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 this post

Link to post
Share on other sites
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 :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!