1 2 /** 3 * This code was originally written by Mark Kilgard (mjk@nvidia.com) (c) 1997 4 * see: http://www.opengl.org/developers/code/mjktips/TexFont/TexFont.html 5 */ 6 7 /*************************************************************************** 8 text.h - Font manager for .txf fonts 9 ------------------- 10 begin : Mon Jul 7 2003 11 copyright : (C) 2003 by Gabor Torok 12 email : cctorok@yahoo.com 13 ***************************************************************************/ 14 15 /*************************************************************************** 16 * * 17 * This program is free software; you can redistribute it and/or modify * 18 * it under the terms of the GNU General Public License as published by * 19 * the Free Software Foundation; either version 2 of the License, or * 20 * (at your option) any later version. * 21 * * 22 ***************************************************************************/ 23 24 #ifndef TEXT_H 25 #define TEXT_H 26 #pragma once 27 28 29 /** 30 *@author Gabor Torok 31 */ 32 33 #define TXF_FORMAT_BYTE 0 34 #define TXF_FORMAT_BITMAP 1 35 36 struct TexGlyphInfo { 37 unsigned short c; /* Potentially support 16-bit glyphs. */ 38 unsigned char width; 39 unsigned char height; 40 signed char xoffset; 41 signed char yoffset; 42 signed char advance; 43 char dummy; /* Space holder for alignment reasons. */ 44 short x; 45 short y; 46 }; 47 48 struct TexGlyphVertexInfo { 49 GLfloat t0[2]; 50 GLshort v0[2]; 51 GLfloat t1[2]; 52 GLshort v1[2]; 53 GLfloat t2[2]; 54 GLshort v2[2]; 55 GLfloat t3[2]; 56 GLshort v3[2]; 57 GLfloat advance; 58 }; 59 60 struct TexFont { 61 GLuint texobj; 62 int tex_width; 63 int tex_height; 64 int max_ascent; 65 int max_descent; 66 int num_glyphs; 67 int min_glyph; 68 int range; 69 unsigned char *teximage; 70 TexGlyphInfo *tgi; 71 TexGlyphVertexInfo *tgvi; 72 TexGlyphVertexInfo **lut; 73 }; 74 75 enum { 76 MONO, TOP_BOTTOM, LEFT_RIGHT, FOUR 77 }; 78 79 /* byte swap a 32-bit value */ 80 #define SWAPL(x, n) { \ 81 n = ((char *) (x))[0];\ 82 ((char *) (x))[0] = ((char *) (x))[3];\ 83 ((char *) (x))[3] = n;\ 84 n = ((char *) (x))[1];\ 85 ((char *) (x))[1] = ((char *) (x))[2];\ 86 ((char *) (x))[2] = n; } 87 88 /* byte swap a short */ 89 #define SWAPS(x, n) { \ 90 n = ((char *) (x))[0];\ 91 ((char *) (x))[0] = ((char *) (x))[1];\ 92 ((char *) (x))[1] = n; } 93 94 class TexturedText { 95 private: 96 97 char *lastError; 98 int useLuminanceAlpha; 99 std::string filename; 100 TexFont *txf; 101 102 public: 103 TexturedText(); 104 ~TexturedText(); 105 106 txfErrorString()107 inline char *txfErrorString() { 108 return lastError; 109 } 110 111 112 TexFont *txfLoadFont( std::string& filename ); 113 114 void txfUnloadFont(); 115 116 GLuint txfEstablishTexture( GLuint texobj, 117 GLboolean setupMipmaps ); 118 119 void txfBindFontTexture(); 120 121 void txfGetStringMetrics( char *string, 122 int len, 123 int *width, 124 int *max_ascent, 125 int *max_descent ); 126 127 void txfRenderGlyph( int c ); 128 129 void txfRenderString( char *string, 130 int len ); 131 132 void txfRenderFancyString( char *string, 133 int len ); 134 135 private: 136 TexGlyphVertexInfo *getTCVI( int c ); 137 int txfInFont( int c ); 138 DECLARE_NOISY_OPENGL_SUPPORT(); 139 }; 140 141 #endif 142