00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _GLTEXT_
00031 #define _GLTEXT_
00032
00033 #include <string>
00034 #include <map>
00035
00036 #include "opengl.h"
00037 #include <ft2build.h>
00038 #include FT_FREETYPE_H
00039
00040 #define START_CHAR 33
00041 #define NUM_CHARS 93
00042 #define NUM_FONTS 10
00043
00044 struct char_info_t {
00045 float width;
00046 float height;
00047 float bearing_x;
00048 float bearing_y;
00049 float advance;
00050 float tex_x_start;
00051 float tex_x_end;
00052 float tex_y_end;
00053 };
00054
00055 struct font_slot_t {
00056 float scale;
00057 float newline_distance;
00058 float color[4];
00059 char *tex_buf;
00060 char_info_t letter[NUM_CHARS];
00061 GLuint tex_id;
00062 };
00063
00064 typedef std::map<int, int> font_size_map_t;
00065 typedef std::map<std::string, font_size_map_t> font_map_t;
00066
00067 class GLText
00068 {
00069 protected:
00070 static font_slot_t *fonts[NUM_FONTS];
00071 font_slot_t *current_font;
00072 int current_slot;
00073 static font_map_t fontMap;
00074
00075 public:
00076 GLText();
00077 virtual ~GLText();
00078
00079 static const font_slot_t& GetFont(char *font_file, int size);
00080 static int RenderText(const char* str, const font_slot_t &font);
00081 static int LoadFont(char *font_file, int size);
00082 static void DelFont(int slot);
00083 static int SetActiveFont(int slot);
00084 static int CheckFont(int slot);
00085 static int GetActiveFont(void);
00086 static int PrintString(const char str[]);
00087 static void PrintStrings(const char str[]);
00088 static int PrintString(std::string str);
00089 static void PrintStrings(std::string str);
00090 static void SetScale(float scale);
00091 static void SetColor(float r, float g, float b, float a);
00092 static float StrLen(const char str[]);
00093
00094 protected:
00095 int loadFont(char *font_file, int size);
00096 void delFont(int slot);
00097 int setActiveFont(int slot);
00098 int checkFont(int slot);
00099 int getActiveFont(void);
00100 int printString(const char str[]);
00101 void printStrings(const char str[]);
00102 void setScale(float scale);
00103 void setColor(float r, float g, float b, float a);
00104 float strLen(const char str[]);
00105 void setScale(char_info_t *character, float scale);
00106
00107 };
00108
00109
00110 class GLConsole
00111 {
00112 protected:
00113 static char consoleBuf[81*25];
00114 static bool visible;
00115
00116 public:
00117 static void PaintConsole();
00118 static void ClearConsole();
00119 static void PrintToConsole(const char str[]);
00120
00121 static void SetVisible(bool b) { visible = b; }
00122 static bool IsVisible() { return visible; }
00123 };
00124
00125 #endif //_GLTEXT_