-
Notifications
You must be signed in to change notification settings - Fork 1
/
FreeTypeFont.h
76 lines (60 loc) · 2.4 KB
/
FreeTypeFont.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Based on code from NeHe's OpenGl website
#ifndef FREETYPEFONT_H
#define FREETYPEFONT_H
// FreeType Headers
#include <ft2build.h>
#include <freetype/freetype.h>
#include <freetype/ftglyph.h>
#include <freetype/ftoutln.h>
#include <freetype/fttrigon.h>
// OpenGL Headers
#include <windows.h> //(the GL headers need it)
#include <GL/gl.h>
#include <GL/glu.h>
// Some STL headers
#include <vector>
#include <string>
// Using the STL exception library increases the
// chances that someone else using our code will corretly
// catch any exceptions that we throw.
#include <stdexcept>
// MSVC will spit out all sorts of useless warnings if
// you create vectors of strings, this pragma gets rid of them.
#pragma warning(disable: 4786)
// Wrap everything in a namespace, that we can use common
// function names like "print" without worrying about
// overlapping with anyone else's code.
namespace freetype
{
// Inside of this namespace, give ourselves the ability
// to write just "vector" instead of "std::vector"
using std::vector;
// Ditto for string.
using std::string;
// This holds all of the information related to any
// freetype font that we want to create.
class font_data
{
public:
float h; ///< Holds the height of the font.
GLuint * textures; ///< Holds the texture id's
GLuint list_base; ///< Holds the first display list id
// The init function will create a font of
// of the height h from the file fname.
void init(const char * fname, unsigned int h);
~font_data(){ clean(); }
// Free all the resources associated with the font.
void clean();
};
//The flagship function of the library - this thing will print
//out text at window Coordinates x,y, using the font ft_font.
//The current modelview matrix will also be applied to the text.
void print(const font_data &ft_font, float x, float y, const char *fmt, ...);
// print one char at a time - useful for roguelike engine :)
void printChar(const font_data &ft_font, int x, int y, const char c);
// call before calling printChar ( ideally you are going to call printChar a bunch of times)
void prePrintChar(const font_data &ft_font);
// call after printChar ( any number of times)
void postPrintChar();
} // freetype
#endif // FREETYPEFONT_H