GLText.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 5 -*- */
00002 
00003 /*
00004  * Combination of a first person action and a real time strategy battle game.
00005  */
00006 
00007 /*
00008  * GLText.h
00009  * MetalWarriors
00010  * $Revision: 1.21 $
00011  *
00012  * Created by Daniel Aarno on Sun Oct 12 2003.
00013  * Copyright (c) 2003 Daniel Aarno and Erik Ytterberg - All rights reserved.
00014  *
00015  *     This program is free software; you can redistribute it and/or modify
00016  *     it under the terms of the GNU General Public License as published by
00017  *     the Free Software Foundation; either version 2 of the License, or
00018  *     (at your option) any later version.
00019  *
00020  *     This program is distributed in the hope that it will be useful,
00021  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *     GNU General Public License for more details.
00024  *
00025  *     You should have received a copy of the GNU General Public License
00026  *     along with this program; if not, write to the Free Software
00027  *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
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_

Generated on Sun Mar 11 15:33:23 2007 for MetalWarriors by  doxygen 1.4.7