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

glfont.h File Reference

Go to the source code of this file.

Compounds

struct  GLFONT
struct  GLFONTCHAR

Defines

#define TRUE   1
#define FALSE   0

Functions

int glFontCreate (GLFONT *Font, char *FileName, int Tex)
void glFontDestroy (GLFONT *Font)
void glFontBegin (GLFONT *Font)
void glFontEnd (void)
void glFontTextOut (char *String, float x, float y, float z)


Define Documentation

#define FALSE   0
 

Definition at line 13 of file glfont.h.

Referenced by CheckForCollision(), CheckPointInSphere(), ColorDialogHook(), glFontCreate(), IsZeroVector(), LoadSplines(), SetGLTexture(), StartProc(), WinMain(), and WndProc().

#define TRUE   1
 

Definition at line 9 of file glfont.h.

Referenced by CheckForCollision(), CheckPointInSphere(), ColorDialogHook(), glFontCreate(), IsZeroVector(), SetGLTexture(), StartProc(), WinMain(), and WndProc().


Function Documentation

void glFontBegin GLFONT   Font
 

Definition at line 95 of file glfont.cpp.

References GLFONT::Char, and GLFONT::Tex.

Referenced by DrawMyText().

00096 {
00097     //Save pointer to font structure
00098     if (Font->Char != NULL)
00099         glFont = Font;
00100     else
00101         glFont = NULL;
00102 
00103     //Bind to font texture
00104     glBindTexture(GL_TEXTURE_2D, Font->Tex);
00105 }

int glFontCreate GLFONT   Font,
char *    FileName,
int    Tex
 

Definition at line 26 of file glfont.cpp.

References GLFONT::Char, FALSE, GLFONT::IntEnd, GLFONT::IntStart, GLFONT::Tex, GLFONT::TexHeight, GLFONT::TexWidth, and TRUE.

Referenced by InitGL().

00027 {
00028     FILE *Input;
00029     char *TexBytes;
00030     int Num;
00031 
00032     //Open font file
00033     if ((Input = fopen(FileName, "rb")) == NULL)
00034         return FALSE;
00035 
00036     //Read glFont structure
00037     fread(Font, sizeof(GLFONT), 1, Input);
00038 
00039     //Save texture number
00040     Font->Tex = Tex;
00041 
00042     //Get number of characters
00043     Num = Font->IntEnd - Font->IntStart + 1;
00044 
00045     //Allocate memory for characters
00046     if ((Font->Char = (GLFONTCHAR *)malloc(
00047         sizeof(GLFONTCHAR) * Num)) == NULL)
00048         return FALSE;
00049 
00050     //Read glFont characters
00051     fread(Font->Char, sizeof(GLFONTCHAR), Num, Input);
00052 
00053     //Get texture size
00054     Num = Font->TexWidth * Font->TexHeight * 2;
00055 
00056     //Allocate memory for texture data
00057     if ((TexBytes = (char *)malloc(Num)) == NULL)
00058         return FALSE;
00059 
00060     //Read texture data
00061     fread(TexBytes, sizeof(char), Num, Input);
00062 
00063     //Set texture attributes
00064     glBindTexture(GL_TEXTURE_2D, Font->Tex);
00065     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
00066         GL_CLAMP);
00067     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
00068         GL_CLAMP);
00069     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
00070         GL_LINEAR);
00071     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
00072         GL_LINEAR);
00073     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
00074         GL_MODULATE);
00075 
00076     //Create texture
00077     glTexImage2D(GL_TEXTURE_2D, 0, 2, Font->TexWidth,
00078         Font->TexHeight, 0, GL_LUMINANCE_ALPHA,
00079         GL_UNSIGNED_BYTE, (void *)TexBytes);
00080 
00081     //Clean up
00082     free(TexBytes);
00083     fclose(Input);
00084 
00085     //Return pointer to new font
00086     return TRUE;
00087 }

void glFontDestroy GLFONT   Font
 

Definition at line 89 of file glfont.cpp.

References GLFONT::Char.

Referenced by WndProc().

00090 {
00091     //Free character memory
00092     free(Font->Char);
00093 }

void glFontEnd void   
 

Definition at line 107 of file glfont.cpp.

Referenced by DrawMyText().

00108 {
00109     //Font no longer current
00110     glFont = NULL;
00111 }

void glFontTextOut char *    String,
float    x,
float    y,
float    z
 

Definition at line 113 of file glfont.cpp.

References GLFONT::Char, GLFONTCHAR::dx, GLFONTCHAR::dy, GLFONT::IntStart, GLFONTCHAR::tx1, GLFONTCHAR::tx2, GLFONTCHAR::ty1, and GLFONTCHAR::ty2.

Referenced by DrawMyText().

00115 {
00116     int Length, i;
00117     GLFONTCHAR *Char;
00118 
00119     //Return if we don't have a valid glFont
00120     if (glFont == NULL)
00121         return;
00122 
00123     //Get length of string
00124     Length = strlen(String);
00125 
00126     //Begin rendering quads
00127     glBegin(GL_QUADS);
00128 
00129     //Loop through characters
00130     for (i = 0; i < Length; i++)
00131     {
00132         //Get pointer to glFont character
00133         Char = &glFont->Char[(int)String[i] -
00134             glFont->IntStart];
00135 
00136         //Specify vertices and texture coordinates
00137         glTexCoord2f(Char->tx1, Char->ty1);
00138         glVertex3f(x, y, z);
00139         glTexCoord2f(Char->tx1, Char->ty2);
00140         glVertex3f(x, y - Char->dy, z);
00141         glTexCoord2f(Char->tx2, Char->ty2);
00142         glVertex3f(x + Char->dx, y - Char->dy, z);
00143         glTexCoord2f(Char->tx2, Char->ty1);
00144         glVertex3f(x + Char->dx, y, z);
00145 
00146         //Move to next character
00147         x += Char->dx;
00148     }
00149 
00150     //Stop rendering quads
00151     glEnd();
00152 }


Generated on Fri Dec 23 05:20:20 2005 for Portals by doxygen1.2.15