]> git.mxchange.org Git - flightgear.git/blob - src/GUI/SafeTexFont.hxx
Autopilot: clean up the helpers code (which drives the various /internal/) properties...
[flightgear.git] / src / GUI / SafeTexFont.hxx
1 // Copyright (C) 2008  Tim Moore
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16
17 #ifndef FLIGHTGEAR_SAFETEXFONT_HXX
18 #define FLIGHTGEAR_SAFETEXFONT_HXX 1
19
20 #include <string>
21
22 #include <plib/fnt.h>
23
24 namespace flightgear
25 {
26 /**
27  * Subclass of plib's fntTexFont that defers the loading of the font
28  * texture until just before rendering, insuring that it happens in
29  * the proper graphics context. 
30  */
31 class SafeTexFont : public fntTexFont
32 {
33 public:
34     SafeTexFont() : _status(e_NOT_LOADED) {}
35     /** Load the texture for this font.
36      * @param mag OpenGL texture magnification; default is GL_NEAREST
37      * @param min OpenGL texture minification; default is
38      * GL_LINEAR_MIPMAP_LINEAR.
39      * @return the plib value FNT_FALSE if the font file doesn't
40      * exist; otherwise returns FNT_TRUE.
41      */
42     int load(const char *fname, GLenum mag = GL_NEAREST, 
43              GLenum min = GL_LINEAR_MIPMAP_LINEAR);
44     void begin();
45     void putch(sgVec3 curpos, float pointsize, float italic, char c);
46     void puts(sgVec3 curpos, float pointsize, float italic, const char *s);
47     enum FontStatus
48     {
49         e_ERROR = -1,
50         e_NOT_LOADED = 0,
51         e_LOADED = 1
52     };
53     FontStatus getStatus() { return _status; }
54     std::string& fntError() { return _error; }
55 protected:
56     bool ensureTextureLoaded();
57     std::string _name;
58     std::string _error;
59     GLenum _mag;
60     GLenum _min;
61     FontStatus _status;
62 };
63 }
64 #endif