source: git/src/glbitmapfont.h @ 9ea7c01

stereo-2025
Last change on this file since 9ea7c01 was 2279fbed, checked in by Olly Betts <olly@…>, 4 months ago

Clean up OpenGL header inclusion

Probe for whether we have GL/glu.h or OpenGL/glu.h instead of checking
if APPLE is defined.

Fix the probe for GL/glext.h - we need to include gl.h first, but
had a hard-coded GL/gl.h which means this probe would always fail
on macOS.

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[a1614eb]1//
2//  glbitmapfont.h
3//
4//  Draw text using glBitmap.
5//
[7eac11e]6//  Copyright (C) 2011-2022 Olly Betts
[a1614eb]7//
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.
12//
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.
17//
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
21//
22
23#ifndef GLBITMAPFONT_H_INCLUDED
24#define GLBITMAPFONT_H_INCLUDED
25
26#include "wx.h"
27
28class BitmapFont {
29    enum {
[36b4cd7]30        // The highest character point to generate an OpenGL list for.
[a1614eb]31        //
[36b4cd7]32        // We can't generate a GL list for every Unicode character, so we
33        // generate them for the first BITMAPFONT_MAX_CHAR characters and then
34        // use glBitmap directly to draw other characters if they are needed.
35        //
36        // FIXME: We could perhaps even store strings consisting of only the
37        // first 256 points as ISO8859-1.
[a1614eb]38        BITMAPFONT_MAX_CHAR = 256
39    };
40
[a3f83057]41    int gllist_base = 0;
[a1614eb]42
[a3f83057]43    mutable const unsigned char * extra_data = nullptr;
[6e94014]44
[a3f83057]45    mutable int * extra_chars = nullptr;
[36b4cd7]46
47    unsigned char char_width[BITMAPFONT_MAX_CHAR];
48
[cba8bf34]49    void init_extra_chars() const;
50
51    int glyph_width(wxChar ch) const;
52
[36b4cd7]53    void write_glyph(wxChar ch) const;
[a1614eb]54
[614d60b]55    wxString font_file;
56
[7eac11e]57    int font_size;
58
[a1614eb]59  public:
60
[a3f83057]61    BitmapFont() { }
[a1614eb]62
[0273042]63    ~BitmapFont();
[a1614eb]64
[7eac11e]65    bool load(const wxString & font_file, bool double_size);
[a1614eb]66
[7eac11e]67    int get_font_size() const { return font_size; }
[a1614eb]68
69    void get_text_extent(const wxChar *s, size_t len, int *width, int *height) const {
70        if (width) {
71            int total_width = 0;
72            while (len--) {
[6f9b20d]73                int ch = *s++;
[a1614eb]74                if (ch < BITMAPFONT_MAX_CHAR)
75                    total_width += char_width[ch];
[d4d6909]76                else
[cba8bf34]77                    total_width += glyph_width(ch);
[a1614eb]78            }
79            *width = total_width;
80        }
81        if (height) {
82            *height = get_font_size() + 1;
83        }
84    }
85
86    void write_string(const wxChar *s, size_t len) const;
87};
88
89#endif
Note: See TracBrowser for help on using the repository browser.