5

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
Piotr Chojnacki
  • 6,837
  • 5
  • 34
  • 65

1 Answers1

3

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.

Tom van der Woerdt
  • 29,532
  • 7
  • 72
  • 105
  • Thanks for an answer, but I think I'm not able to do that as the only function I call for rendering is (it's from FTGL library): font->Render(text,-1, pos); So I don't think I have any way to modify the rendering area. – Piotr Chojnacki Jan 01 '13 at 14:16
  • Like I said, I don't know much about the FTGL library, but is it possible that you're maybe using wrong modelview/projection matrices, causing the transformation from vertices to pixel locations to go wrong? *Something* is causing the texture(s) to sample. – Tom van der Woerdt Jan 01 '13 at 14:18
  • I have no idea how could I actually check if I'm using "wrong modelview matrix" as You say. From what I see, everything else seems to be correct - I am using also other textures to draw gui components' backgrounds and they are being displayed properly (I mean, pixels are in the right places). – Piotr Chojnacki Jan 01 '13 at 16:35