View Full Version : font problem, and im out of ideas....

11-26-2008, 01:55 AM

ive been struggling with font rendering for more than a week now, i just cant solve my problem. so i hope someone with more experience can help me out.

basically, im rendering freetype fonts in a similar way to nehe #43.

it more or less seems ok unless i scale the fonts, but even slight scaling can produce ugly artifacts. of course i expect some artifacts, but not the kind seen in this picture (the "u" is totally joined at the top by some kind of unwanted filtering)


the other artifact i get is that the top or bottom of certain letters often looks clipped.

any ideas would be much appreciated.

also... could anybody tell me with confidence if you should use gluortho2d with w-1 and h-1 or just w and h.... there seems no clear statement on this on the net....

11-26-2008, 04:26 AM
first, i dont know how you create and load ttfs but make sure you check your final texture and the characters inside it if they all correct. second, the texture coordinates (st) of each char should be correct when you draw them. third, if font is stored in texture, then enable proper texture filtering (linear) if scaled.

11-26-2008, 04:32 AM
Looks like the top row sometimes wraps to the bottom.
Try this to avoid bleeding interpolation :
int width = next_p2( bitmap.width + 1);
int height = next_p2( bitmap.rows + 1);

the other artifact i get is that the top or bottom of certain letters often looks clipped.
Sure this part looks messy. try adding some space :

float x=(float)bitmap.width / (float)width,
y=(float)(bitmap.rows + 1) / (float)height;

glTexCoord2d(0,0); glVertex2f(0,bitmap.rows+1);
glTexCoord2d(0,y); glVertex2f(0,0);
glTexCoord2d(x,y); glVertex2f(bitmap.width,0);
glTexCoord2d(x,0); glVertex2f(bitmap.width,bitmap.rows+1);

I am pretty sure you have to use w h for gluortho2d.
They are extremum planes/lines.

example with w = 2 :

* = pixel center, half coordinates
| = edge of pixel, integer coordinates.

11-26-2008, 04:40 AM
you might consider switching to a lib that does all font related stuff for you.

11-26-2008, 05:55 AM

thanks a lot, thats really helped. the wrapping problem seemed the cause for the "u".

ive still got the clipping problem, but it seems slightly better following your suggestion. what i want to try now is expand your idea of shifting the texture mapping, by having 1 blank row of pixels at the top and bottom of the quad im mapping the glyph onto.

i was trying to do this by using the TEXTURE_RECTANGLE_EXT so that i can position the texture on the quad in pixels rather than as a fraction. but cant get it to work. could somebody please post a few lines of code of how to get that to work?

*much appreciated* - i see some light at the end of the tunnel!!!

11-26-2008, 06:17 AM
well im pretty intent on doing myself, but still, if you know of any good libs id be interested to check them out...

11-26-2008, 06:37 AM
Well, try to stay away from TEXTURE_RECTANGLE_EXT. It will not really help anyway, float precision is not the issue here.
If you disable texture filtering, what do you get ?

11-26-2008, 07:10 AM
not sure yet, i havent figured out how to do the pixel offsetting thing yet. will try that a bit later this afternoon. massive thanks for your help!!!

11-26-2008, 08:34 AM
ok i solved the problem...

for anyone interested...

- first make sure the allocated bitmap is at least 2 pixels higher and wider than the glyph

- during the transfer of glyph to bitmap, offset the write pos by 1 pixel in x and y dimension. (ie creates a pixel spacing around the glyph)

- then bind the bitmap to the texture, pretending the glyph is 2 pixels bigger than the orignal face (to preserve the pixel border).

- add a glTranslatef during the call list, to compensate for the pixel

im not sure this last step is working quite right yet, but basically im happy for now that this method can deliver the results i need, so i can now carry on developing my api.

thanks for the help!