-
Notifications
You must be signed in to change notification settings - Fork 0
Home
cbaakman edited this page Oct 5, 2018
·
8 revisions
Text GL can be used for displaying text in the 3D library OpenGL, but it does more than that. For example: it can tell you on which character the mouse cursor is currently pointing. This enables you to have selectable text.
Useful OpenGL tutorials can be found here: http://nehe.gamedev.net/
Your font data has to be an SVG file, according to the standards at https://www.w3.org/TR/SVG11/fonts.html. Used variables are:
- bbox: the bounding box for the glyphs. Text GL assumes no glyph is rendered outside this box.
- glyph d: the path, or control points of the glyphs, this describes how to draw the glyph in 2D
- horiz-adv-x: the character horizontal coordinate incrementation, either per glyph or for the whole font
- horiz-origin-x: the character horizontal bearing, either per glyph or for the whole font
- horiz-origin-y: the character vertical bearing, either per glyph or for the whole font
- hkern k,g1/u1, g2/u2: the horizontal kerning values, can be single character combo's or group combo's (kerning by class)
Text GL currently assumes that glyphs are positioned in horizontal lines, from left to right. So Arabic or Chinese texts are not supported.
To generate SVG font files easily, use fontforge: https://fontforge.github.io/en-US/
Parsing only requires a single function, but that function needs a C++ istream object as input:
#include <iostream>
#include <fstream>
#include <text-gl/text.h>
using namespace TextGL;
FontData fontData;
std::ifstream is;
is.open("my-font.svg");
if (!is.good())
std::cerr << "Error opening file." << std::endl;
ParseSVGFontData(is, fontData);