source: git/src/fnt.h @ 5627cbb

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since 5627cbb was 5627cbb, checked in by Olly Betts <olly@…>, 14 years ago
  • Fix to build with a "unicode" build of wx.
  • Add "Copy" button to the About dialog to copy the system info to the clipboard.
  • List OpenGL extensions last, since there are usually lots of them with a modern gfx card.
  • When processing survey data, auto-scroll the log window until we've reported a warning or error.
  • Put the survey data log window in a splitter in the standard frame rather than having a separate frame for it.

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

  • Property mode set to 100644
File size: 2.7 KB
Line 
1//
2//  fnt.h
3//
4//  Draw text using texture mapped fonts.
5//
6//  Copyright (C) 2003,2004,2006 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) 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(strlen((const char *)s), GL_UNSIGNED_BYTE, s);
90        } else if (sizeof(wxChar) == 2) {
91            size_t len = 0;
92            while (s[len]) ++len;
93            glCallLists(len, GL_UNSIGNED_SHORT, s);
94        } else if (sizeof(wxChar) == 4) {
95            size_t len = 0;
96            while (s[len]) ++len;
97            glCallLists(len, GL_UNSIGNED_INT, s);
98        }
99        glPopMatrix();
100    }
101#if 0
102    void putch(int x, int y, char c) {
103        glMatrixMode(GL_MODELVIEW);
104        glPushMatrix();
105        glLoadIdentity();
106        glTranslated(x, y, 0);
107        glCallList(list_base + (unsigned char)c);
108        glPopMatrix();
109    }
110#endif
111
112};
113
114#endif
Note: See TracBrowser for help on using the repository browser.