00001 // texturefont.h 00002 // 00003 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net> 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 00010 #ifndef _TEXTUREFONT_H_ 00011 #define _TEXTUREFONT_H_ 00012 00013 #include <vector> 00014 #include <string> 00015 #include <iostream> 00016 #include <celutil/basictypes.h> 00017 00018 00019 class TextureFont 00020 { 00021 public: 00022 TextureFont(); 00023 ~TextureFont(); 00024 00025 void render(wchar_t) const; 00026 void render(const std::string&) const; 00027 00028 int getWidth(const std::string&) const; 00029 int getWidth(int c) const; 00030 int getMaxWidth() const; 00031 int getHeight() const; 00032 00033 int getMaxAscent() const; 00034 void setMaxAscent(int); 00035 int getMaxDescent() const; 00036 void setMaxDescent(int); 00037 00038 int getTextureName() const; 00039 00040 void bind(); 00041 00042 bool buildTexture(); 00043 00044 public: 00045 struct TexCoord 00046 { 00047 float u, v; 00048 }; 00049 00050 struct Glyph 00051 { 00052 Glyph(unsigned short _id) : __id(_id) {}; 00053 00054 unsigned short __id; 00055 unsigned short width; 00056 unsigned short height; 00057 short x; 00058 short xoff; 00059 short y; 00060 short yoff; 00061 short advance; 00062 TexCoord texCoords[4]; 00063 }; 00064 00065 enum { 00066 TxfByte = 0, 00067 TxfBitmap = 1, 00068 }; 00069 00070 private: 00071 void addGlyph(const Glyph&); 00072 const TextureFont::Glyph* getGlyph(wchar_t) const; 00073 void rebuildGlyphLookupTable(); 00074 00075 private: 00076 int maxAscent; 00077 int maxDescent; 00078 int maxWidth; 00079 00080 int texWidth; 00081 int texHeight; 00082 unsigned char* fontImage; 00083 unsigned int texName; 00084 00085 std::vector<Glyph> glyphs; 00086 00087 const Glyph** glyphLookup; 00088 unsigned int glyphLookupTableSize; 00089 00090 public: 00091 static TextureFont* load(std::istream& in); 00092 }; 00093 00094 TextureFont* LoadTextureFont(const std::string&); 00095 00096 #endif // _TEXTUREFONT_H_ 00097
1.4.1