Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ugly font after resizing, OpenGL

I'll start with an image:

enter image description here

Above image presents text achieved in two different ways, both used the same type of font - Arial, bold, size 11.

The one at the bottom was created in image editing program, and the one at the top in my OpenGL application. To be more precise, using FTExtrudeFont from FTGL library:

font_ptr font(new FTExtrudeFont(filename.c_str()));

My question is, why is it drawn like this? I assume the reason for this might be different resizing algorithms, but if so, how can I achieve this better-looking font (the bottom one) in my OpenGL application?

EDIT:

To render a font, I do only call this one function:

font->Render(text,         // Text to be displayed
             -1,           // Line length, which by default is left as -1
             pos);         // Position in which to draw text
like image 353
Piotr Chojnacki Avatar asked Oct 22 '22 20:10

Piotr Chojnacki


1 Answers

This looks like something that would be caused by texture sampling in OpenGL. It happens when the texture you're drawing (a font, in this case) isn't the same size as the quad you draw it on.

Easy solution: make sure that the texture size matches the area that's drawn on the screen. Don't render a 14px font to a 12px area, but use a 12px font or a 14px area.

In your question you mention that your font is 'size 11'. I'm not aware of the details of the FTGL library, but I assume that there's a call that will tell you the best dimensions for a specific string you can draw. Don't use your own math to calculate these, use the library. As long as you got the dimensions right, the issue you're having shouldn't happen.

like image 162
Tom van der Woerdt Avatar answered Oct 27 '22 09:10

Tom van der Woerdt