/*
 * (C) Copyright Chris B. Kaynor 2006
 * All Rights Reserved.
 *
 * CONTACT: chris@kaynor.net
*/

#ifndef CBK_GENERIC_DRAWING_ROUTINES
#define CBK_GENERIC_DRAWING_ROUTINES

//Data for all tanks
cbk_object_data_tank Tanks[Maximum_Tanks + 1];
long Number_Tanks = 0;

//Data for all projectiles
cbk_object_data_projectile Projectiles[Maximum_Projectiles];
long Number_Projectiles = -1;

//Data for all static objects
cbk_object_data_static Objects[Maximum_Objects];
long Number_Objects = -1;

//Data for all particle emitters
idr_particle_system ParticleEmitters[Maximum_Tanks + 1];
long Number_Particles = -1;

//Varibles to hold texture IDs
UINT GroundTexture        =  1; //            Procedual Texture

UINT SkyTexture           =  2; //            "texture_sky.jpg"
UINT TankTexture          =  3; //            "texture_tank.jpg"

UINT BeginScreenTexture   =  4; //            "screen_begin.jpg"
UINT DeathScreenTexture   =  5; //            "screen_death.jpg"
UINT VictoryScreenTexture =  6; //            "screen_victory.jpg"

UINT NumberTexture[]     = { 7, // '0'        "number_0.jpg"
                             8, // '1'        "number_1.jpg"
							 9, // '2'        "number_2.jpg"
						    10, // '3'        "number_3.jpg"
							11, // '4'        "number_4.jpg"
							12, // '5'        "number_5.jpg"
							13, // '6'        "number_6.jpg"
							14, // '7'        "number_7.jpg"
							15, // '8'        "number_8.jpg"
							16, // '9'        "number_9.jpg"
                            17, // '-'        "number_-.jpg"
                            18, // '/'        "number_Slash.jpg"
                            19, // '%'        "number_%.jpg"
                            20};// '.'        "number_Decimal.jpg"

UINT ScoreTexture         = 21; // 'Score:'   "text_Score.jpg"
UINT LivesTexture         = 22; // 'Lives:'   "text_Lives.jpg"
UINT TanksAliveTexture    = 23; // 'Tanks:'   "text_Tanks.jpg"
UINT LevelTexture         = 24; // 'Level:'   "text_Level.jpg"
UINT AccuracyTexture      = 25; // 'Accu.:'   "text_Accuracy.jpg"

void DrawGround(void)
{
	const GLfloat Object_Plane_T[] = {0, 0, 1};

	const GLfloat fStep = 1.0f;
	const GLfloat y = 0.0f;
	GLfloat iStrip, iRun;

	glPushMatrix();
	glLoadIdentity();
    gluLookAt( 0.0, 2.0,  -5.0,    // eye position
	           0.0, 1.25,  5.0,    // point the eye is looking at
	           0.0, 1.0,   0.0);   // "up" direction

	glBindTexture(GL_TEXTURE_2D, GroundTexture);
	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
	glTexGenfv(GL_T, GL_OBJECT_PLANE, Object_Plane_T);

	glMatrixMode(GL_TEXTURE);
		glPushMatrix();
		glLoadIdentity();
		glScalef(0.5, 0.5, 0.5);
		glTranslatef(Tanks[0].get_position().GetValue(1), Tanks[0].get_position().GetValue(3), 0);
	glMatrixMode(GL_MODELVIEW);

	glRotatef(-Tanks[0].get_rotation().GetValue(1), 0, 1, 0);

	for(iStrip = -HorizonDistance; iStrip <= HorizonDistance; iStrip += fStep)
	{
		if (GroundDrawMode == 0) {
			glBegin(GL_TRIANGLE_STRIP);
		} else {
			glPointSize(5);
			glBegin(GL_POINTS);
		}
		glNormal3f(0.0f, 1.0f, 0.0f);

		for(iRun = -HorizonDistance; iRun <= HorizonDistance; iRun += fStep)
		{
			glVertex3f(iStrip, y, iRun);
			glVertex3f(iStrip + fStep, y, iRun);
		}

		glEnd();
	}

	glMatrixMode(GL_TEXTURE);
		glPopMatrix();
	glMatrixMode(GL_MODELVIEW);

	glPopMatrix();
}

void DrawSky(void) {
	const GLfloat fStep = 2.0f;
	const GLfloat z = HorizonDistance * 0.9;
	GLfloat iStrip, iRun;

    glDisable(GL_DEPTH_TEST);
	glDisable(GL_FOG);
	glDisable(GL_LIGHTING);

	glBindTexture(GL_TEXTURE_2D, SkyTexture);

	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); //GL_OBJECT_LINEAR);
	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); //GL_OBJECT_LINEAR);

	glMatrixMode(GL_TEXTURE);
		glPushMatrix();
		glLoadIdentity();
		glTranslatef(Tanks[0].get_rotation().GetValue(1) / -60, 0, 0);
		glScalef(5, 5, 5);
	glMatrixMode(GL_MODELVIEW);

	glLineWidth(10);
	glPushMatrix();
	glLoadIdentity();
    gluLookAt( 0.0, 2.0,  -5.0,    // eye position
	           0.0, 1.25,  5.0,    // point the eye is looking at
	           0.0, 1.0,   0.0);   // "up" direction
	glRotatef(90, 1, 0, 0);

	for(iStrip = -10; iStrip <= 10; iStrip += fStep)
	{
		if (SkyDrawMode == 0) {
			glBegin(GL_TRIANGLE_STRIP);
		} else {
			glPointSize(5);
			glBegin(GL_POINTS);
		}
		glNormal3f(0.0f, 1.0f, 0.0f);

		for(iRun = 0; iRun >= -10; iRun -= fStep)
		{
			glVertex3f(iStrip,         5, iRun);
			glVertex3f(iStrip + fStep, 5, iRun);
		}

		glEnd();
	}

	glPopMatrix();	

	glMatrixMode(GL_TEXTURE);
		glPopMatrix();
	glMatrixMode(GL_MODELVIEW);

	glEnable(GL_FOG);
    glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);

}

void SetupLighting(void) {
	glEnable(GL_LIGHT0);
	glPushMatrix();
	glLoadIdentity();
	glLightfv(GL_LIGHT0, GL_AMBIENT, AmbientLight0Color);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseLight0Color);
	glLightfv(GL_LIGHT0, GL_POSITION, Light0Position);
	glPopMatrix();
}

static void init_ground_texture( void )
{
	#define CUBE_TEX_SIZE 32
	#define CUBE_TEX_REPEAT 16

	GLubyte image[CUBE_TEX_SIZE][CUBE_TEX_SIZE][3];

	GLint Value;
	GLint i, j;

	glGenTextures(1, &GroundTexture);

	glBindTexture(GL_TEXTURE_2D, GroundTexture);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	/* make colored checkerboard cube faces */
	for (i = 0; i < CUBE_TEX_SIZE; i++) {
		for (j = 0; j < CUBE_TEX_SIZE; j++) {
			Value = (((i / CUBE_TEX_REPEAT) + (j / CUBE_TEX_REPEAT)) % 2);
			if (Value == 1) {
				image[i][j][0] = 0;
				image[i][j][1] = 0;
				image[i][j][2] = 0;
			} else {
				image[i][j][0] = 255;
				image[i][j][1] = 255;
				image[i][j][2] = 255;
			}
		}
	}

	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, true);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, CUBE_TEX_SIZE, CUBE_TEX_SIZE, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, 1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}

static void init_sky_texture( void )
{
	Load_Texture(SkyTexture, "texture_sky.jpg");

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); //GL_MIRRORED_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

static void init_tank_texture( void )
{
	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, true);

	Load_Texture(TankTexture, "texture_tank.jpg");

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

static void init_begin_texture( void )
{
	Load_Texture(BeginScreenTexture, "screen_begin.jpg");

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

static void init_death_texture( void )
{
	Load_Texture(DeathScreenTexture, "screen_death.jpg");

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

static void init_victory_texture( void )
{
	Load_Texture(VictoryScreenTexture, "screen_victory.jpg");

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

static void init_number_textures( void )
{
	char FileNameChar[20];
	LPSTR *FileName;

	for (long x = 0; x <= 9; x++) {
		sprintf(FileNameChar, "number_%i.jpg", x);
		FileName = new LPSTR(FileNameChar);

		Load_Texture(NumberTexture[x], *FileName);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	}
	Load_Texture(NumberTexture[10], "number_-.jpg");
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	Load_Texture(NumberTexture[11], "number_Slash.jpg");
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	Load_Texture(NumberTexture[12], "number_%.jpg");
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	Load_Texture(NumberTexture[13], "number_Decimal.jpg");
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

static void init_text_textures( void )
{
	Load_Texture(ScoreTexture, "text_Score.jpg");
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	Load_Texture(LivesTexture, "text_Lives.jpg");
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	Load_Texture(TanksAliveTexture, "text_Tanks.jpg");
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	Load_Texture(LevelTexture, "text_Level.jpg");
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	Load_Texture(AccuracyTexture, "text_Accuracy.jpg");
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

void DrawFullScreenPlane(void) {
	glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);

	glDisable(GL_LIGHTING);
	glDisable(GL_FOG);
	glDisable(GL_TEXTURE_GEN_S); //X
	glDisable(GL_TEXTURE_GEN_T); //Z

	glLoadIdentity();
	gluLookAt( 0.0,  0.0,  1.5,    // eye position
			   0.0,  0.0,  0.0,    // point the eye is looking at
			   0.0,  1.0,  0.0);   // "up" direction

	glBegin(GL_QUADS);
		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 0,  0);
		glVertex3f  (-1, -1,  0);

		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 0,  1);
		glVertex3f  (-1,  1,  0);

		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 1,  1);
		glVertex3f  ( 1,  1,  0);

		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 1,  0);
		glVertex3f  ( 1, -1,  0);
	glEnd();

	glEnable(GL_TEXTURE_GEN_S); //X
	glEnable(GL_TEXTURE_GEN_T); //Z
	glEnable(GL_LIGHTING);
	glEnable(GL_FOG);
}

void DrawScorePlane(GLfloat X, GLfloat Y, UINT TextTexture, long Number) {
	glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);

	static const GLfloat Divisor = 30;

	if (Number >  99999999) {Number =  99999999;}
	if (Number < -99999999) {Number = -99999999;}

	long NumberIndex = 0;
	char Numbers[10];
	sprintf(Numbers, "%-+5.0i", Number);
	if (Number == 0) {Numbers[0] = '0';}

	glDisable(GL_LIGHTING);
	glDisable(GL_FOG);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_TEXTURE_GEN_S); //X
	glDisable(GL_TEXTURE_GEN_T); //Z

	X -= 810;
	Y += 770;

	glLoadIdentity();
	gluLookAt( 0.0,  0.0,  40.0,    // eye position
			   0.0,  0.0,   0.0,    // point the eye is looking at
			   0.0,  1.0,   0.0);   // "up" direction

	glBindTexture(GL_TEXTURE_2D, TextTexture);
	glBegin(GL_QUADS);
		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 0,  0);
		glVertex3f  ( X / Divisor,  Y / Divisor,  0);

		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 0,  1);
		glVertex3f  ( X / Divisor,  (Y + 32)  / Divisor,  0);

		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 1,  1);
		glVertex3f  ( (X + 128) / Divisor,  (Y + 32)  / Divisor,  0);

		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 1,  0);
		glVertex3f  ( (X + 128)  / Divisor,  Y  / Divisor,  0);
	glEnd();
	X += 128;
	for (long x = 0; x <= 5; x++) {
		NumberIndex = 0;
		switch (Numbers[x]) {
			case '.':
				NumberIndex++;
			case '%':
				NumberIndex++;
			case '/':
				NumberIndex++;
			case '-':
				NumberIndex++;
			case '9':
				NumberIndex++;
			case '8':
				NumberIndex++;
			case '7':
				NumberIndex++;
			case '6':
				NumberIndex++;
			case '5':
				NumberIndex++;
			case '4':
				NumberIndex++;
			case '3':
				NumberIndex++;
			case '2':
				NumberIndex++;
			case '1':
				NumberIndex++;
			case '0': //Run if the value is a number or an '-'
				glBindTexture(GL_TEXTURE_2D, NumberTexture[NumberIndex]);
				glBegin(GL_QUADS);
				glNormal3f  ( 0,  0,  1);
				glTexCoord2f( 0,  0);
				glVertex3f  ( X / Divisor,  Y / Divisor,  0);

				glNormal3f  ( 0,  0,  1);
				glTexCoord2f( 0,  1);
				glVertex3f  ( X / Divisor,  (Y + 32)  / Divisor,  0);

				glNormal3f  ( 0,  0,  1);
				glTexCoord2f( 1,  1);
				glVertex3f  ( (X + 32) / Divisor,  (Y + 32)  / Divisor,  0);

				glNormal3f  ( 0,  0,  1);
				glTexCoord2f( 1,  0);
				glVertex3f  ( (X + 32)  / Divisor,  Y  / Divisor,  0);
				glEnd();
				X += 32;
				break;
			case ' ':
				X += 32;
				break;
		}
	}

	glEnable(GL_TEXTURE_GEN_S); //X
	glEnable(GL_TEXTURE_GEN_T); //Z
	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_FOG);
}


void DrawScorePlane(GLfloat X, GLfloat Y, UINT TextTexture, char *String, long StringLength) {
	glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);

	static const GLfloat Divisor = 30;

	long NumberIndex = 0;

	glDisable(GL_LIGHTING);
	glDisable(GL_FOG);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_TEXTURE_GEN_S); //X
	glDisable(GL_TEXTURE_GEN_T); //Z

	X -= 810;
	Y += 770;

	glLoadIdentity();
	gluLookAt( 0.0,  0.0,  40.0,    // eye position
			   0.0,  0.0,   0.0,    // point the eye is looking at
			   0.0,  1.0,   0.0);   // "up" direction

	glBindTexture(GL_TEXTURE_2D, TextTexture);
	glBegin(GL_QUADS);
		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 0,  0);
		glVertex3f  ( X / Divisor,  Y / Divisor,  0);

		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 0,  1);
		glVertex3f  ( X / Divisor,  (Y + 32)  / Divisor,  0);

		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 1,  1);
		glVertex3f  ( (X + 128) / Divisor,  (Y + 32)  / Divisor,  0);

		glNormal3f  ( 0,  0,  1);
		glTexCoord2f( 1,  0);
		glVertex3f  ( (X + 128)  / Divisor,  Y  / Divisor,  0);
	glEnd();
	X += 128;
	for (long x = 0; x <= StringLength; x++) {
		NumberIndex = 0;
		switch (String[x]) {
			case '.':
				NumberIndex++;
			case '%':
				NumberIndex++;
			case '/':
				NumberIndex++;
			case '-':
				NumberIndex++;
			case '9':
				NumberIndex++;
			case '8':
				NumberIndex++;
			case '7':
				NumberIndex++;
			case '6':
				NumberIndex++;
			case '5':
				NumberIndex++;
			case '4':
				NumberIndex++;
			case '3':
				NumberIndex++;
			case '2':
				NumberIndex++;
			case '1':
				NumberIndex++;
			case '0': //Run if the value is a number or an '-'
				glBindTexture(GL_TEXTURE_2D, NumberTexture[NumberIndex]);
				glBegin(GL_QUADS);
				glNormal3f  ( 0,  0,  1);
				glTexCoord2f( 0,  0);
				glVertex3f  ( X / Divisor,  Y / Divisor,  0);

				glNormal3f  ( 0,  0,  1);
				glTexCoord2f( 0,  1);
				glVertex3f  ( X / Divisor,  (Y + 32)  / Divisor,  0);

				glNormal3f  ( 0,  0,  1);
				glTexCoord2f( 1,  1);
				glVertex3f  ( (X + 32) / Divisor,  (Y + 32)  / Divisor,  0);

				glNormal3f  ( 0,  0,  1);
				glTexCoord2f( 1,  0);
				glVertex3f  ( (X + 32)  / Divisor,  Y  / Divisor,  0);
				glEnd();
				X += 32;
				break;
			case ' ':
				X += 32;
				break;
		}
	}

	glEnable(GL_TEXTURE_GEN_S); //X
	glEnable(GL_TEXTURE_GEN_T); //Z
	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_FOG);
}

#endif //CBK_GENERIC_DRAWING_ROUTINES