source: git/src/fnt.h @ 967723f

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since 967723f was 967723f, checked in by Olly Betts <olly@…>, 14 years ago

src/fnt.h,src/gla-gl.cc: Pass the length of the string to
fntTexFont::puts() rather than recalculating it inside the
method.

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@3401 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 2.6 KB
Line 
1//
2//  fnt.h
3//
4//  Draw text using texture mapped fonts.
5//
6//  Copyright (C) 2003,2004,2006,2010 Olly Betts
7//
8//     Based on code from PLIB - http://plib.sourceforge.net
9//     Copyright (C) 1998,2002  Steve Baker
10//     Relicensed under the GNU GPL as permitted by the GNU LGPL
11//
12//  This program is free software; you can redistribute it and/or modify
13//  it under the terms of the GNU General Public License as published by
14//  the Free Software Foundation; either version 2 of the License, or
15//  (at your option) any later version.
16//
17//  This program is distributed in the hope that it will be useful,
18//  but WITHOUT ANY WARRANTY; without even the implied warranty of
19//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20//  GNU General Public License for more details.
21//
22//  You should have received a copy of the GNU General Public License
23//  along with this program; if not, write to the Free Software
24//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25//
26
27#ifndef _FNT_H_
28#define _FNT_H_  1
29
30#ifdef __APPLE__
31#  include <OpenGL/gl.h>
32#else
33#  include <GL/gl.h>
34#endif
35
36#include "wx.h" // For wxChar
37
38#include <string.h>
39
40#define FNT_MAXCHAR 256
41
42class fntTexFont {
43  private:
44    GLuint texture;
45
46    int fnt_size;
47
48    int list_base;
49
50    /* Nominal baseline widths */
51    int widths[FNT_MAXCHAR];
52
53  public:
54
55    fntTexFont() : texture(0), fnt_size(0), list_base(0)
56    {
57    }
58
59    ~fntTexFont()
60    {
61        if (list_base != 0) glDeleteLists(list_base + 32, 256 - 32);
62        if (texture != 0) glDeleteTextures(1, &texture);
63    }
64
65    bool load(const char *fname);
66
67    bool hasGlyph(char c) const { return widths[(unsigned char)c] >= 0; }
68
69    int getFontSize() const { return fnt_size; }
70
71    void getTextExtent(const wxChar *s, int *width, int *height) const {
72        if (width) {
73            int w = -1;
74            while (*s) w += widths[(unsigned char)*s++];
75            if (w < 0) w = 0;
76            *width = w;
77        }
78        if (height) *height = fnt_size + 1;
79    }
80
81    void puts(int x, int y, const wxChar *s, size_t len) const {
82        glBindTexture(GL_TEXTURE_2D, texture);
83        glMatrixMode(GL_MODELVIEW);
84        glPushMatrix();
85        glLoadIdentity();
86        glTranslated(x, y, 0);
87        glListBase(list_base);
88        if (sizeof(wxChar) == 1) {
89            glCallLists(len, GL_UNSIGNED_BYTE, s);
90        } else if (sizeof(wxChar) == 2) {
91            glCallLists(len, GL_UNSIGNED_SHORT, s);
92        } else if (sizeof(wxChar) == 4) {
93            glCallLists(len, GL_UNSIGNED_INT, s);
94        }
95        glPopMatrix();
96    }
97#if 0
98    void putch(int x, int y, char c) {
99        glMatrixMode(GL_MODELVIEW);
100        glPushMatrix();
101        glLoadIdentity();
102        glTranslated(x, y, 0);
103        glCallList(list_base + (unsigned char)c);
104        glPopMatrix();
105    }
106#endif
107
108};
109
110#endif
Note: See TracBrowser for help on using the repository browser.