4 extern TGAImageRec texture;
6 void Text::LoadFontTexture(char *fileName)
12 LOG(std::string("Loading font texture...") + fileName);
14 Game::LoadTexture(fileName, &FontTexture, false, false);
17 //LoadTGA( fileName );
18 unsigned char fileNamep[256];
19 CopyCStringToPascal(fileName,fileNamep);
21 upload_image( fileNamep ,1);
26 if ( texture.bpp == 24 )
31 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
33 if(!FontTexture)glGenTextures( 1, &FontTexture );
34 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
36 glBindTexture( GL_TEXTURE_2D, FontTexture);
37 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
38 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
40 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
45 glDeleteLists(base, 512);
50 void Text::BuildFont() // Build Our Font Display List
52 float cx; // Holds Our X Character Coord
53 float cy; // Holds Our Y Character Coord
60 LOG("Font already created...");
64 // base=glGenLists(256); // Creating 256 Display Lists
65 base=glGenLists(512); // Creating 256 Display Lists
66 glBindTexture(GL_TEXTURE_2D, FontTexture); // Select Our Font Texture
67 for (loop=0; loop<256; loop++) // Loop Through All 256 Lists
69 cx=float(loop%16)/16.0f; // X Position Of Current Character
70 cy=float(loop/16)/16.0f; // Y Position Of Current Character
72 glNewList(base+loop,GL_COMPILE); // Start Building A List
73 glBegin(GL_QUADS); // Use A Quad For Each Character
74 glTexCoord2f(cx,1-cy-0.0625f+.001); // Texture Coord (Bottom Left)
75 glVertex2i(0,0); // Vertex Coord (Bottom Left)
76 glTexCoord2f(cx+0.0625f,1-cy-0.0625f+.001); // Texture Coord (Bottom Right)
77 glVertex2i(16,0); // Vertex Coord (Bottom Right)
78 glTexCoord2f(cx+0.0625f,1-cy-.001); // Texture Coord (Top Right)
79 glVertex2i(16,16); // Vertex Coord (Top Right)
80 glTexCoord2f(cx,1-cy-+.001); // Texture Coord (Top Left)
81 glVertex2i(0,16); // Vertex Coord (Top Left)
82 glEnd(); // Done Building Our Quad (Character)
83 glTranslated(10,0,0); // Move To The Right Of The Character
84 glEndList(); // Done Building The Display List
85 } // Loop Until All 256 Are Built
86 for (loop=256; loop<512; loop++) // Loop Through All 256 Lists
88 cx=float((loop-256)%16)/16.0f; // X Position Of Current Character
89 cy=float((loop-256)/16)/16.0f; // Y Position Of Current Character
91 glNewList(base+loop,GL_COMPILE); // Start Building A List
92 glBegin(GL_QUADS); // Use A Quad For Each Character
93 glTexCoord2f(cx,1-cy-0.0625f+.001); // Texture Coord (Bottom Left)
94 glVertex2i(0,0); // Vertex Coord (Bottom Left)
95 glTexCoord2f(cx+0.0625f,1-cy-0.0625f+.001); // Texture Coord (Bottom Right)
96 glVertex2i(16,0); // Vertex Coord (Bottom Right)
97 glTexCoord2f(cx+0.0625f,1-cy-.001); // Texture Coord (Top Right)
98 glVertex2i(16,16); // Vertex Coord (Top Right)
99 glTexCoord2f(cx,1-cy-+.001); // Texture Coord (Top Left)
100 glVertex2i(0,16); // Vertex Coord (Top Left)
101 glEnd(); // Done Building Our Quad (Character)
102 glTranslated(8,0,0); // Move To The Right Of The Character
103 glEndList(); // Done Building The Display List
104 } // Loop Until All 256 Are Built
107 void Text::glPrint(float x, float y, char *string, int set, float size, float width, float height) // Where The Printing Happens
113 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
114 glBindTexture(GL_TEXTURE_2D, FontTexture); // Select Our Font Texture
115 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
116 glDisable(GL_LIGHTING);
118 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
119 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
120 glPushMatrix(); // Store The Projection Matrix
121 glLoadIdentity(); // Reset The Projection Matrix
122 glOrtho(0,width,0,height,-100,100); // Set Up An Ortho Screen
123 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
124 glPushMatrix(); // Store The Modelview Matrix
126 glTranslated(x,y,0); // Position The Text (0,0 - Bottom Left)
127 glScalef(size,size,1); // Reset The Modelview Matrix
128 glListBase(base-32+(128*set)); // Choose The Font Set (0 or 1)
129 glCallLists(strlen(string),GL_BYTE,string); // Write The Text To The Screen
130 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
131 glPopMatrix(); // Restore The Old Projection Matrix
132 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
133 glPopMatrix(); // Restore The Old Projection Matrix
134 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
135 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
138 void Text::glPrint(float x, float y, char *string, int set, float size, float width, float height,int start,int end) // Where The Printing Happens
144 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
145 glBindTexture(GL_TEXTURE_2D, FontTexture); // Select Our Font Texture
146 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
147 glDisable(GL_LIGHTING);
149 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
150 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
151 glPushMatrix(); // Store The Projection Matrix
152 glLoadIdentity(); // Reset The Projection Matrix
153 glOrtho(0,width,0,height,-100,100); // Set Up An Ortho Screen
154 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
155 glPushMatrix(); // Store The Modelview Matrix
157 glTranslated(x,y,0); // Position The Text (0,0 - Bottom Left)
158 glScalef(size,size,1); // Reset The Modelview Matrix
159 glListBase(base-32+(128*set)); // Choose The Font Set (0 or 1)
160 glCallLists(end-start,GL_BYTE,&string[start]); // Write The Text To The Screen
161 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
162 glPopMatrix(); // Restore The Old Projection Matrix
163 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
164 glPopMatrix(); // Restore The Old Projection Matrix
165 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
166 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
170 void Text::glPrintOutline(float x, float y, char *string, int set, float size, float width, float height) // Where The Printing Happens
176 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
177 glBindTexture(GL_TEXTURE_2D, FontTexture); // Select Our Font Texture
178 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
179 glDisable(GL_LIGHTING);
181 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
182 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
183 glPushMatrix(); // Store The Projection Matrix
184 glLoadIdentity(); // Reset The Projection Matrix
185 glOrtho(0,width,0,height,-100,100); // Set Up An Ortho Screen
186 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
187 glPushMatrix(); // Store The Modelview Matrix
189 glTranslated(x,y,0); // Position The Text (0,0 - Bottom Left)
190 glScalef(size,size,1); // Reset The Modelview Matrix
191 glListBase(base-32+(128*set)+256); // Choose The Font Set (0 or 1)
192 glCallLists(strlen(string),GL_BYTE,string); // Write The Text To The Screen
193 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
194 glPopMatrix(); // Restore The Old Projection Matrix
195 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
196 glPopMatrix(); // Restore The Old Projection Matrix
197 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
198 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
201 void Text::glPrintOutline(float x, float y, char *string, int set, float size, float width, float height,int start,int end) // Where The Printing Happens
207 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
208 glBindTexture(GL_TEXTURE_2D, FontTexture); // Select Our Font Texture
209 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
210 glDisable(GL_LIGHTING);
212 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
213 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
214 glPushMatrix(); // Store The Projection Matrix
215 glLoadIdentity(); // Reset The Projection Matrix
216 glOrtho(0,width,0,height,-100,100); // Set Up An Ortho Screen
217 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
218 glPushMatrix(); // Store The Modelview Matrix
220 glTranslated(x,y,0); // Position The Text (0,0 - Bottom Left)
221 glScalef(size,size,1); // Reset The Modelview Matrix
222 glListBase(base-32+(128*set)+256); // Choose The Font Set (0 or 1)
223 glCallLists(end-start,GL_BYTE,&string[start]); // Write The Text To The Screen
224 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
225 glPopMatrix(); // Restore The Old Projection Matrix
226 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
227 glPopMatrix(); // Restore The Old Projection Matrix
228 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
229 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
232 void Text::glPrintOutlined(float x, float y, char *string, int set, float size, float width, float height) // Where The Printing Happens
235 glPrintOutline( x-2*size, y-2*size, string, set, size*2.5/2, width, height);
237 glPrint( x, y, string, set, size, width, height);
240 void Text::glPrintOutlined(float r, float g, float b, float x, float y, char *string, int set, float size, float width, float height) // Where The Printing Happens
243 glPrintOutline( x-2*size, y-2*size, string, set, size*2.5/2, width, height);
245 glPrint( x, y, string, set, size, width, height);
257 glDeleteLists(base, 512);
260 if (FontTexture) glDeleteTextures( 1, &FontTexture );