4 // Draw text using glBitmap.
6 // Copyright (C) 2011,2013,2014 Olly Betts
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef GLBITMAPFONT_H_INCLUDED
24 #define GLBITMAPFONT_H_INCLUDED
30 #elif defined HAVE_OPENGL_GL_H
31 # include <OpenGL/gl.h>
36 // The highest character point to generate an OpenGL list for.
38 // We can't generate a GL list for every Unicode character, so we
39 // generate them for the first BITMAPFONT_MAX_CHAR characters and then
40 // use glBitmap directly to draw other characters if they are needed.
42 // FIXME: We could perhaps even store strings consisting of only the
43 // first 256 points as ISO8859-1.
44 BITMAPFONT_MAX_CHAR
= 256
49 mutable const unsigned char * extra_data
;
51 mutable int * extra_chars
;
53 unsigned char char_width
[BITMAPFONT_MAX_CHAR
];
55 void init_extra_chars() const;
57 int glyph_width(wxChar ch
) const;
59 void write_glyph(wxChar ch
) const;
65 BitmapFont() : gllist_base(0), extra_data(0), extra_chars(0) { }
69 glDeleteLists(gllist_base
, BITMAPFONT_MAX_CHAR
);
72 bool load(const wxString
& font_file
);
75 int get_font_size() const { return 16; }
77 void get_text_extent(const wxChar
*s
, size_t len
, int *width
, int *height
) const {
82 if (ch
< BITMAPFONT_MAX_CHAR
)
83 total_width
+= char_width
[ch
];
85 total_width
+= glyph_width(ch
);
90 *height
= get_font_size() + 1;
94 void write_string(const wxChar
*s
, size_t len
) const;