Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

font.h

00001 // $Id: font.h,v 1.1.1.1 2003/06/24 15:33:12 sjcomp Exp $
00002 // Copyright (c) 2003, Alexander Shyrokov aka SJ
00003 // E-mail: sjcomp[@]users.sourceforge.com
00004 // Web:    http://sjgui.sourceforge.net
00005 //
00006 // This code is under BSD license agreement.
00007 //
00008 // Alexander Shyrokov makes no representations about the suitability of this software 
00009 // for any purpose. It is provided "AS IS" without express or implied warranty.
00010 
00011 #if !defined(SJFONT_H_INCLUDED)
00012 #define SJFONT_H_INCLUDED
00013 
00014 #include "globals.h"
00015 
00016 namespace sjgui{
00017 
00028 class CFont
00029 {
00030     static int def_font_size; // font size as generated for the texture
00031     // Font Texture Storage Space
00032     static GLuint   m_uiTexture; 
00033     // Base Display List For The Font
00034     static GLuint   m_uiBase; 
00035     /* 
00036      Creates font from array of unsigned char values.
00037      \see LoadFont
00038     */
00039     static bool CreateFont(unsigned char* font_texture,int font_width,int font_height);
00040     /* Choose The Font Set (0 or 1). */
00041     void SetListBase(){glListBase(m_uiBase-32+(128*m_iSet));}
00042     /* Select texture. */
00043     void BindTexture(){glBindTexture(GL_TEXTURE_2D, m_uiTexture);}
00044 // for ease of drawing text
00045     /*
00046      Controls if texturing was enabled.
00047      Used to store this information when drawing text,
00048      so that at the end the states could be restored.
00049     */
00050     GLboolean   m_yTxt; 
00051     /*
00052      Controls if blending was enabled.
00053      Used to store this information when drawing text,
00054      so that at the end the states could be restored.
00055     */
00056     GLboolean   m_yBlend;
00057     /* 
00058      Normal or Italic text.
00059      Set 0 to get normal text.
00060      Set 1 to get italic text.
00061     */ 
00062     int         m_iSet; 
00063     float       m_fScale; // Serves to scale down the font to the required size
00064     int         m_iFontSize; // Size of the font
00065 public:
00067     enum eFontStyles{NORMAL=0,ITALIC=1};
00068     CFont()
00069     {
00070         m_fScale=1.0f;
00071         m_yTxt=false;
00072         m_yBlend=false;
00073         m_iSet=0;
00074         m_iFontSize=def_font_size;
00075     }
00080     void SetFontStyle(eFontStyles style){if(style==NORMAL)m_iSet=0;else m_iSet=1;};
00082     float GetFontScale(){return m_fScale;}
00084     void SetFontSize(int i){m_iFontSize=i;m_fScale=(float)i/def_font_size;}
00086     int GetFontSize(){return m_iFontSize;};
00100     static bool LoadFont(unsigned char* font_texture=NULL,int font_width=256,int font_height=256);
00102     static void DestroyFont();
00104     void FontDrawBegin()
00105     {
00106         m_yTxt=glIsEnabled(GL_TEXTURE_2D);
00107         // Enable Texture Mapping
00108         glEnable(GL_TEXTURE_2D);
00109         // To make our font transparent!
00110         m_yBlend=glIsEnabled(GL_BLEND);
00111         glEnable(GL_BLEND);
00112     };
00114     void FontDrawEnd()
00115     {
00116         // return to Texture Mapping
00117         if(m_yTxt)
00118             glEnable(GL_TEXTURE_2D);
00119         else
00120             glDisable(GL_TEXTURE_2D);
00121         if(m_yBlend)
00122             glEnable(GL_BLEND);
00123         else
00124             glDisable(GL_BLEND);
00125     };
00126     // iX, iY coordinates, fScale scale of the font, msg to be printed
00127     // with length uiLen, and color fC, which is 4 values vector
00133     void FontDraw(int iX, int iY, const char* msg, unsigned int uiLen,float* fC4fv);
00134 };
00135 
00136 } // namespace sjgui
00137 
00138 #endif // !defined(SJFONT_H_INCLUDED)
sjgui logo
Quick Links:

 News
 Description
 Screen Shots
 Projects
 Downloads
 Source Code
 Help/FAQ
 Want to help?
 Credits
 Disclaimer


Documentation:

 Documentation
 Reference
 Lessons


Useful links:

sjcomp logo
sjcomp

opengl logo

nehe logo

SourceForge.net Logo

Last modified:


Started by Alexander Shyrokov. Generated at Wed Apr 28 12:31:04 2004 for the sjgui by doxygen 1.3.1. SourceForge.net Logo