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(), WinMain(), and WndProc().

#define TRUE   1
 

Definition at line 9 of file glfont.h.

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


Function Documentation

void glFontBegin GLFONT   Font
 

Definition at line 94 of file glfont.cpp.

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

Referenced by DrawMyText().

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

int glFontCreate GLFONT   Font,
char *    FileName,
int    Tex
 

Definition at line 25 of file glfont.cpp.

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

Referenced by InitGL().

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

void glFontDestroy GLFONT   Font
 

Definition at line 88 of file glfont.cpp.

References GLFONT::Char.

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

void glFontEnd void   
 

Definition at line 106 of file glfont.cpp.

Referenced by DrawMyText().

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

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

Definition at line 112 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().

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


Generated on Fri Dec 23 05:21:21 2005 for Skybox by doxygen1.2.15