5

I started working at this company that uses an 2D OpenGL implementation to show our system's data (which runs on Windows.) The whole system was built with C++ (using C++Builder 2007). Thing is, all the text they print there are pixelized when you zoom in, which I think happens because the text is a bitmap:

Example of the view

From what I know they use the same font files as Windows does. I asked around here on why this happens and the answer I got is that the guy who implemented it (which doesn't work at the company anymore) said fonts on OpenGL are hard and this was the best he could do or something like it.

My question is: is there any simple and effective way to make the text also a vector (the same way those lines in the picture are?) So when I zoom the camera, which happens a lot, they don't pixelize. I have little knowledge of OpenGL and if you have some guide and/or tutorial related to this to point me towards the right direction I'd be very thankful. Basically any material would be great.

diogocarmo
  • 960
  • 1
  • 11
  • 30
  • 1
    The main issue he had with OpenGL is likely that fonts are handled very inconsistently across platforms, and support for them is minimal anyway - but there's probably 3rd party libraries devoted to this (SDL and GLEW provide support, IIRC) – Polar Apr 28 '13 at 14:05
  • I'll look for those libraries, thanks! – diogocarmo Apr 28 '13 at 14:15
  • @AkiSuihkonen if you find them, do share here! Thanks! – diogocarmo Apr 28 '13 at 14:21
  • 1
    This could give some additional ideas: A concept called 'alpha blending with distance fields' allow high resolution / deep zooming into fonts sampled at relatively low resolution. http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf – Aki Suihkonen Apr 28 '13 at 14:28
  • http://stackoverflow.com/questions/5262951/what-is-state-of-the-art-for-text-rendering-in-opengl-as-of-version-4-1 – Ciro Santilli OurBigBook.com Nov 05 '16 at 21:19

4 Answers4

11

Most of OpenGL text rendering libraries come to this: creating bitmaps for the fonts. This means you are going to have problems with scaling and aliasing unless you do some hacks.

One of the popular hacks is Valve's approach: Chris Green. 2007. "Improved Alpha-Tested Magnification for Vector Textures and Special Effects.". You use signed distance field algo to generate your fonts bitmap which then helps you to smooth the text outlines on scale during rendering. Wikidot has the C++ implementation for Distance field generation.

If you stick to NVidia specific hardware, you can try the NVidia Path extension which allows you to render graphics directly on GPU. Remember, it is a NVidia only thing. But in general, signed distance field based approach is the smoothest and easiest to implement.

BTW, freetype-gl uses Valve's approach and also the modern pipeline.

BSMP
  • 4,596
  • 8
  • 33
  • 44
Michael IV
  • 11,016
  • 12
  • 92
  • 223
  • Thanks for the explanation, Michael. It's more clear to me now. I'll definitely check all the links, though the NVidia solution is too specific too our project, I'll read about it just to get some perspective anyway. – diogocarmo Apr 28 '13 at 19:25
  • There's also the Vector Texture Maps method http://alice.loria.fr/index.php/publications.html?Paper=VTM@2005 – datenwolf Apr 29 '13 at 10:30
4

You can try freetype-gl its a library for font rendering in OpenGL.

ugur deniz
  • 41
  • 1
  • 3
  • I'll try tomorrow and then report back, but as others mentioned this library seems to be the solution. Thanks! – diogocarmo Apr 28 '13 at 19:26
0

The issue with using fonts in OpenGL is that they are handled inconsistently across platforms, and that they have minimal support. If you're willing to go with a helper library for OpenGL (SDL comes to mind), then this behaviour will likely be wrapped, meaning that you merely need to provide a suitable font file for them to use.

Polar
  • 186
  • 7
  • 18
-1

You may try out FTOGL4 , the fonts for OpenGL4

  • 1
    Please add some more details. – de. Jul 20 '21 at 17:25
  • FTOGL4 : Vector based Opengl 4 font support. Now available for MS-window 10. FTOGL4 is Opengl 4.0 port of FTGL. Currently, it supports outline, polygon and extrude fonts. https://github.com/Pinakinzaveri61/FTOGL4 – pinakin zaveri Aug 30 '22 at 05:25