Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vector-based fonts on OpenGL

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.

like image 955
diogocarmo Avatar asked Apr 28 '13 13:04

diogocarmo


People also ask

What is a vector based font?

A scalable font made of point-to-point line segments. Like vector-based images, vector fonts are easily scaled but lack the hints and mathematically defined curves of outline fonts, such as Adobe Type 1 and TrueType.

Are fonts in vector?

Outline fonts. Outline fonts or vector fonts are collections of vector images, consisting of lines and curves defining the boundary of glyphs.


2 Answers

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.

like image 83
Michael IV Avatar answered Oct 19 '22 08:10

Michael IV


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

like image 30
ugur deniz Avatar answered Oct 19 '22 08:10

ugur deniz