# Freetype help ( problem positioning characters ) [C++]

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

## Recommended Posts

Heya all, I have got freetype to generate characters for me. I then take the character data and copy them to a single texture. I am padding every character to make its width and height the closest power of 2. e.g 32x32. My problem is the way the characters get drawn. I know I am supposed to offset my start copy/draw positions. What I don't know is where I get these values from. The image below shows my problem. Image Link As you can see characters overlap and some are vertically positioned wrong. How can I solve this problem? Thanks

##### Share on other sites
Here's another image that shows what I actually generate.

As you can see, my only problem is that I need to offset certain characters into their correct positions.

I looked at the documentation and NeHe's tutorial #43. He does some weird translating in order to get the positions right.

He casts each glyph to an FT_BitmapGlyph to get two positions, left and top.

The freetype docs say:

Quote:
 left The left-side bearing, i.e., the horizontal distance from the current pen position to the left border of the glyph bitmap.top The top-side bearing, i.e., the vertical distance from the current pen position to the top border of the glyph bitmap. This distance is positive for upwards-y!

Then theres some other the 'advance vector' from the generated glyph character itself ( FTGlyph ). I don't know what this really does.

I would appreciate it if someone who got freetype character positioning right to reply. Doesn't matter how you used it, just what you ddid to get it right.

Thanks

##### Share on other sites
Hmm... I haven't looked at the NeHe tutorial, but I don't use the FT_BitmapGlyph struct at all and don't have any problems with my text:
	FT_UInt res;	FT_GlyphSlot slot;	res = FT_Load_Char((FT_Face)face, code, FT_LOAD_RENDER);	// get quick pointer to FT glyph data	slot = ((FT_Face)face)->glyph;	// store glyph offset and advance data	xoffs   = slot->bitmap_left;	yoffs   = slot->bitmap_top;	advance = ((float)slot->advance.x) / 64.0f;	// convert .6 fixed to float

I then render the glyph like so:
	// calculate base positions	x1 = x + ((float)xoffs * scale);	y1 =     ((float)yoffs * scale);	// ---[ render glyph at (x1, y1) here ]---	// increment position	x += advance * scale;

Hope this helps!

##### Share on other sites
I think there's a parameter named bitmap_top you need to add somewhere. Let me look it up. . .

Edit

From bpoint's post:
xoffs   = slot->bitmap_left;yoffs   = slot->bitmap_top;

• 10
• 16
• 14
• 18
• 15