C++ openGL : Lag issue

Started by
19 comments, last by pkiskool 15 years, 1 month ago
I'm developing a software for my masters degree where I simulate a 2D fluid flow in a cavity. I represent each fluid particles with a circle. As flow comes in the cavity, everything is all smooth and fine, until the program displays more than x number of fluid particles on the screen. x number is probably around... 40 ~ 50. A serious lag starts from then, where everything is delayed and non-smooth. It behaves like a comic book slides instead of a smooth video like motion. Part of the reason is probably due to the specs of my PC, but I was wondering if there is a way to improve this by playing around with the code? I will include the openGL part of my code:

//HEADER FILES
#include "glut.h"

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <string>
#include <stdlib.h>

#define TINY 1.0e-20;
#define NRANSI
#define GL_PI 3.1415f

#include "nrutil.h"
#include "nrutil.cpp"
#include "ludcmp.h"
#include "lubksb.h"
#include "matcalc2.h" 
#include "matcalc3.h" 
#include "front.h"

// Rotation amounts
static GLdouble xRot = 0.0f;
static GLdouble yRot = 0.0f;
static GLdouble zRot = 0.0f;

static GLdouble eyeX = 0.0f;
static GLdouble eyeY = -1.0f;
static GLdouble eyeZ = 2500.0f;

static GLdouble centerX = 0.0f;
static GLdouble centerY = 0.0f;
static GLdouble centerZ = 0.0f;

static GLdouble upX = 0.0f;
static GLdouble upY = 0.0f;
static GLdouble upZ = 1.0f;

static GLdouble scale = 1.0f;

bool GeometryFlag;
bool ZoomInFlag;
bool ZoomOutFlag;
bool NumFlag;
bool LegendFlag=true;
int numb=0;
GLdouble y, x;	
double gridspace = 12.0f;
unsigned int now, last;


///////////////////////////////////////////////////////////
// Setup the rendering state

//////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
	{
         .
         .
         bunch of stuff here
         .
         .
  
// Restore transformations
				glPopMatrix();

				// Flush drawing commands
				glutSwapBuffers();

				glutPostRedisplay();

				//change buffer, 2 buffers enables smooth drawing in one go

				glMatrixMode(GL_MODELVIEW);
				glLoadIdentity();

				gluLookAt(eyeX,eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);


	}

	void SetupRC(void)
    {
		// Black background
		glClearColor(0.0f, 0.0f, 0.0f, 1.0f );

    }

void ChangeSize(int w, int h)
	{
		GLfloat fAspect;

		// Prevent a divide by zero
		if(h == 0)
			h = 1;

		// Set Viewport to window dimensions
		glViewport(0, 0, w, h);

		fAspect = (GLfloat)w/(GLfloat)h;

		// Reset coordinate system
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();

		// Produce the perspective projection
		gluPerspective(5.0f, fAspect, 1.0, 6000.0);

	}

void OtherKeys(unsigned char key, int z, int a)
	{	

		if(key == 't')	{	// 't' starts the flow during manual mode
			if (GeometryFlag==false)
				GeometryFlag=true;

			else if (GeometryFlag==true)
				GeometryFlag=false;
		}

		if (GeometryFlag==true) {
			front();
		}
						
		if (SolutionFlag==true) {
			matcalc3();
			SolutionFlag=false;
		}	


		if(key == 'n')	{	// 'n' toggles the node number display on/off
			if (NumFlag==false)
				NumFlag=true;

			else if (NumFlag==true)
				NumFlag=false;
		}


		if(key == 'p')	{	// 'p' pauses the flow during auto mode
			cout << "Paused." << "\n";
			system ("pause");
		}


		if (key == 'l') {	// 'l' toggles the legend displa on/off
			if (LegendFlag==false)
				LegendFlag=true;

			else if (LegendFlag==true)
				LegendFlag=false;
		}


		if (key == ']') {	// ']' increases the time step during flow
			t += 1;
		}

		if (key == '[') {	// ']' increases the time step during flow
			t -= 1;
		}


		if(key == 'q') {	// 'q' zoodel_x in the view
			eyeZ += 25;
		}


		if(key == 'a') {	// 'a' zoodel_x out the view
			eyeZ -= 25;
		}

	}


void SpecialKeys(int key, int x, int y)
	{
		if(key == GLUT_KEY_UP) {	//rotates about x
			xRot -= 5.0f;
		}

		if(key == GLUT_KEY_DOWN) {
			xRot += 5.0f;
		}

		if(key == GLUT_KEY_LEFT) {	//rotates about y
			yRot -= 5.0f;
		}

		if(key == GLUT_KEY_RIGHT) {
			yRot += 5.0f;
		}

		if(key == GLUT_KEY_HOME) {	//rotates about z
			zRot -= 5.0f;
		}

		if(key == GLUT_KEY_END) {
			zRot += 5.0f;
		}

		if(key == GLUT_KEY_PAGE_UP) {	//pans along x-positive
			eyeX -= 5.0f;
			centerX -= 5.0f;

		}

		if(key == GLUT_KEY_INSERT) {	//pans along x-negative
			eyeX += 5.0f;
			centerX += 5.0f;

		}


		if(zRot > 356.0f)
				zRot = 0.0f;

		if(zRot < -1.0f)
				zRot = 355.0f;

		if(xRot > 356.0f)
				xRot = 0.0f;

		if(xRot < -1.0f)
				xRot = 355.0f;

		if(yRot > 356.0f)
				yRot = 0.0f;

		if(yRot < -1.0f)
				yRot = 355.0f;

	}


int main (int argc, char **argv)
{
	//last = GetTickCount();	//Comment THIS out TO GO MANUAL///////////////////////////////////////////////////////////////////////////////////////////////////

	cout << "Enter distance between the nodes (m): ";
	cin >> del_x;
	cout << "\n";

	cout << "Enter time step (s): ";
	cin >> t;
	cout << "\n";

	cout << "Enter viscosity of resin: ";
	cin >> visco;
	cout << "\n";

	cout << "Enter porosity of fibre: ";
	cin >> poro;
	cout << "\n";

	matcalc2();

		//Draw after each time step

		glutInit(&argc, argv);
		glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
		glutInitWindowSize(1152,864);
		glutCreateWindow("Simulation of VARTM Resin Impregnation Process");
		glutReshapeFunc(ChangeSize);
		glutSpecialFunc(SpecialKeys);
		glutDisplayFunc(RenderScene);
		glutKeyboardFunc(OtherKeys);
		SetupRC();
		glutMainLoop();

}

The specs of my PC: P4 3.4 GHz 3 GB RAM Intel 82945G Express Chipset Family Thanks.
Advertisement
The interesting bits that are most likely making your system slow is where you put

.
.
bunch of stuff here
.
.


We're going to need to see what's in the actual drawing code.
My bad.
The code there is very repetitive so I decided to leave it out but I'll post it.

int i, j;		double k;		GLdouble fCurrSize;			// Save current size		// Clear the window with current clearing color		glClear(GL_COLOR_BUFFER_BIT);		// Save matrix state and do the rotation		glPushMatrix();		glRotatef(xRot, 1.0f, 0.0f, 0.0f);		glRotatef(yRot, 0.0f, 1.0f, 0.0f);		glRotatef(zRot, 0.0f, 0.0f, 1.0f);		glColor3f(1.0f, 1.0f, 1.0f);			//F			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 50,  (gridspace * n)/2-(gridspace/2)+ 5) ;  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 70);			//I			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 53,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 73);			//L			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 56,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 76);			//L			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 59,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 76);			//T			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 65,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 84);			//I			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 68,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 73);			//M			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 71,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 77);			//E			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 74,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 69);			//:			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 77,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 58);			int fill_1, fill_10, fill_100, fill_1000, fill_10000, fill_100000, fill_1000000, fill_10000000;					fill_1 = filltime % 10; 					fill_10 = (filltime  / 10) % 10; 					fill_100 = (filltime  / 100) % 10; 					fill_1000 = (filltime  / 1000) % 10; 					fill_10000 = (filltime  / 10000) % 10; 					fill_100000 = (filltime  / 100000) % 10; 					fill_1000000 = (filltime  / 1000000) % 10;					fill_10000000 = (filltime  / 10000000) % 10;					if (fill_10000000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 80,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_10000000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 80,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_1000000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 83,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_1000000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 83,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 86,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 86,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 89,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 89,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 92,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_1000);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 92,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 95,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_100);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 95,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 98,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 98,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 101,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 101,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}			//S			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 107,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 83);			//E			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 110,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 69);			//C			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 113,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 67);			glEnd();		// Set up x lines			for(y = - ((gridspace * n)/2-(gridspace/2)); y <= (gridspace * n)/2-(gridspace/2); y += gridspace) {			// Set the line width			glLineWidth(2);			// Draw the upper line			glBegin(GL_LINES);			glColor3f(0.1843f, 0.3098f, 0.1843f);				glVertex3f( - ((gridspace * n)/2-(gridspace/2)), y, 0);				glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), y, 0);				glEnd();			// Draw the lower line			glBegin(GL_LINES);			glColor3f(0.1843f, 0.3098f, 0.1843f);				glVertex3f( - ((gridspace * n)/2-(gridspace/2)), y, - 5);				glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), y, - 5);				glEnd();		}		// Set up y lines			for(x = - ((gridspace * n)/2-(gridspace/2)); x <= - ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1); x += gridspace) {			// Set the line width			glLineWidth(2);			// Draw the upper line			glBegin(GL_LINES);			glColor3f(0.1843f, 0.3098f, 0.1843f);				glVertex3f(x, - ((gridspace * n)/2-(gridspace/2)), 0);				glVertex3f(x, ((gridspace * n)/2-(gridspace/2)), 0);				glEnd();			// Draw the lower line			glBegin(GL_LINES);			glColor3f(0.1843f, 0.3098f, 0.1843f);				glVertex3f(x, - ((gridspace * n)/2-(gridspace/2)), -5);				glVertex3f(x, ((gridspace * n)/2-(gridspace/2)), -5);				glEnd();		}			//1D case			if (n==1) {				for(x = - ((gridspace * n)/2-(gridspace/2)); x <= - ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1); x += gridspace) {					// Set the line width					glLineWidth(2);					// Draw the upper line					glBegin(GL_LINES);					glColor3f(0.1843f, 0.3098f, 0.1843f);						glVertex3f(x, - ((gridspace * (n+1)*0.3)/2-(gridspace/2)), 0);						glVertex3f(x, ((gridspace * (n+1)*0.3)/2-(gridspace/2)), 0);						glEnd();					// Draw the lower line					glBegin(GL_LINES);					glColor3f(0.1843f, 0.3098f, 0.1843f);						glVertex3f(x, - ((gridspace * (n+1)*0.3)/2-(gridspace/2)), -5);						glVertex3f(x, ((gridspace * (n+1)*0.3)/2-(gridspace/2)), -5);						glEnd();				}		}		// Set up z lines (4 corners) - thickness to the plate		glBegin(GL_LINES);		glColor3f(0.1843f, 0.3098f, 0.1843f);			glVertex3f( - ((gridspace * n)/2-(gridspace/2)), - ((gridspace * n)/2-(gridspace/2)), 0);			glVertex3f( - ((gridspace * n)/2-(gridspace/2)), - ((gridspace * n)/2-(gridspace/2)), -5);			glEnd();		glBegin(GL_LINES);		glColor3f(0.1843f, 0.3098f, 0.1843f);			glVertex3f( - ((gridspace * n)/2-(gridspace/2)), (gridspace * n)/2-(gridspace/2), 0);			glVertex3f( - ((gridspace * n)/2-(gridspace/2)), (gridspace * n)/2-(gridspace/2), -5);			glEnd();		glBegin(GL_LINES);		glColor3f(0.1843f, 0.3098f, 0.1843f);			glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), - ((gridspace * n)/2-(gridspace/2)), 0);			glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), - ((gridspace * n)/2-(gridspace/2)), -5);			glEnd();		glBegin(GL_LINES);		glColor3f(0.1843f, 0.3098f, 0.1843f);			glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), 0);			glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), -5);			glEnd();				//Draw circle (last wetted node)		for (i=0; i<=n-1; i++)			{    				for (j=1; j<=m; j++) 					{						if (type[i*m+j]==1) { //'o' - display with a hollow white circle														/*glBegin(GL_LINE_LOOP);			//De-bug mode for flow fronts										glColor3f(0.000f, 0.000f, 1.000f);							for (k=0; k<=360; k+=5)								{									glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k) * 3.5) );								}*/							glBegin(GL_TRIANGLE_FAN);							glColor3f(0.000f, 0.000f, 1.000f);							for (k=0; k<=360; k+=5)								{									glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k) * 3.5) );								}							glEnd();								}						else if (type[i*m+j]==0) { //'i' - display with a red cube														glBegin(GL_TRIANGLE_FAN);															glColor3f(1.0f, 0.0f, 0.0f);	//Red							for (k=0; k<=360; k+=5) {								glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k) * 3.5) );							}										glEnd();						}						else if (type[i*m+j]==2) { //'x' - display with a white filled circle							glBegin(GL_TRIANGLE_FAN);								//COLOR CODE								if (pres[i*m+j] >= 0 && pres[i*m+j] < inpres*1000/12*1)  									glColor3f(0.000f, 0.000f, 1.000f);	//Slate Blue								if (pres[i*m+j] >= inpres*1000/12*1 && pres[i*m+j] < inpres*1000/12*2)  									glColor3f(0.000f, 0.5000f, 1.000f);	//Sky Blue								if (pres[i*m+j] >= inpres*1000/12*2 && pres[i*m+j] < inpres*1000/12*3)  									glColor3f(0.000f, 0.800f, 1.000f);	//Medium Torquoise								if (pres[i*m+j] >= inpres*1000/12*3 && pres[i*m+j] < inpres*1000/12*4)  									glColor3f(0.000f, 1.000f, 1.000f);	//Aquamarine								if (pres[i*m+j] >= inpres*1000/12*4 && pres[i*m+j] < inpres*1000/12*5)  									glColor3f(0.000f, 1.000f, 0.600f);	//Spring Green								if (pres[i*m+j] >= inpres*1000/12*5 && pres[i*m+j] < inpres*1000/12*6)  									glColor3f(0.000f, 1.000f, 0.000f);	//Lime Green								if (pres[i*m+j] >= inpres*1000/12*6 && pres[i*m+j] < inpres*1000/12*7)  									glColor3f(0.500f, 0.900f, 0.0f);	//Green								if (pres[i*m+j] >= inpres*1000/12*7 && pres[i*m+j] < inpres*1000/12*8)  									glColor3f(0.800f, 0.900f, 0.000f);	//Medium Spring Green								if (pres[i*m+j] >= inpres*1000/12*8 && pres[i*m+j] < inpres*1000/12*9)  									glColor3f(1.000f, 1.000f, 0.000f);								if (pres[i*m+j] >= inpres*1000/12*9 && pres[i*m+j] < inpres*1000/12*10)  												glColor3f(1.000f, 0.800f, 0.000f);	//Coral								if (pres[i*m+j] >= inpres*1000/12*10 && pres[i*m+j] < inpres*1000/12*11)  									glColor3f(1.000f, 0.500f, 0.000f);								if (pres[i*m+j] >= inpres*1000/12*11 && pres[i*m+j] < inpres*1000/12*12)  																		glColor3f(1.0f, 0.0f, 0.0f); //changed to Red							for (k=0; k<=360; k+=5)								{									glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k) * 3.5) );								}							glEnd();							}						else if (type[i*m+j]==4) { //'+' - display with a white cube							glColor3f(0.9882f, 0.9882f, 0.9882f);										glRectf((-(gridspace * n)/2-(gridspace/2)+j*gridspace) - 4, ( ((gridspace * n)/2-(gridspace/2) - i*gridspace)  ) -4, (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + 4, ( ((gridspace * n)/2-(gridspace/2) - i*gridspace)  ) +4);							glEnd();							}					}//end of for j				}//end of for i								for (i=0; i<=n-1; i++) {				for (j=1; j<=m; j++) {						//Flow front display						if (xseg[i*m+j] <= 0.999 && xseg[i*m+j] >= -0.01) { //xseg has a value							if (type[i*m+j]==3 && (type[i*m+j+1]==1 || type[i*m+j+1]==0 || type[i*m+j+1]==2)) {								//glBegin(GL_LINE_LOOP);								glBegin(GL_TRIANGLE_FAN);								glColor3f(0.000f, 0.000f, 1.000f);	//Blue																for (k=0; k<=360; k+=5)								{									glVertex2f( -(gridspace * n)/2-(gridspace/2)+(j+1)*gridspace - (gridspace*xseg[i*m+j]) + sin(k) * 3.5,  ((gridspace * n)/2 - (gridspace/2) - i*gridspace) + cos(k) * 3.5);								}								glEnd();							}							else if ((type[i*m+j]==1 || type[i*m+j]==0 || type[i*m+j]==2) && type[i*m+j+1]==3) {																							//glBegin(GL_LINE_LOOP);								glBegin(GL_TRIANGLE_FAN);																glColor3f(0.000f, 0.000f, 1.000f);	//Blue																for (k=0; k<=360; k+=5)								{									glVertex2f( -(gridspace * n)/2-(gridspace/2)+j*gridspace + (gridspace*xseg[i*m+j]) + sin(k) * 3.5,  ((gridspace * n)/2-(gridspace/2) - i*gridspace) + cos(k) * 3.5);								}								glEnd();							}						}					}//end of for j				}//end of for i					for (i=0; i<=n-2; i++) {				for (j=1; j<=m; j++) {					 if (yseg[i*m+j] <= 0.999 && yseg[i*m+j] >= -0.01) { //yseg has a value							if (type[i*m+j]==3 && (type[i*m+j+m]==1 || type[i*m+j+m]==0 || type[i*m+j+m]==2)) {								glBegin(GL_TRIANGLE_FAN);										glColor3f(0.000f, 0.000f, 1.000f);	//Blue															for (k=0; k<=360; k+=5)								{									glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k) * 3.5 ,  ((gridspace * n)/2-(gridspace/2) - (i+1)*gridspace) + (gridspace*yseg[i*m+j]) + cos(k) * 3.5);								}								glEnd();							}							else if ( (type[i*m+j]==1 || type[i*m+j]==0 || type[i*m+j]==2) && type[i*m+j+m]==3) {															//glBegin(GL_LINE_LOOP);								glBegin(GL_TRIANGLE_FAN);								 								glColor3f(0.000f, 0.000f, 1.000f);	//Blue														for (k=0; k<=360; k+=5)								{									glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k) * 3.5,  ((gridspace * n)/2-(gridspace/2) - i*gridspace) - (gridspace * yseg[i*m+j]) + cos(k) * 3.5);								}								glEnd();							}						}									}		}			if (NumFlag == true) {			//Set up node number fonts				int num_1, num_10, num_100;				for (y = (gridspace * n)/2-(gridspace/2); y >= - ((gridspace * n)/2-(gridspace/2)); y -= gridspace) {					for (x = - ((gridspace * n)/2-(gridspace/2)) ; x <= - ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1); x += gridspace) {												numb += 1;						num_1 = numb % 10;						num_10 = (numb / 10) % 10;						num_100 = (numb / 100) % 10;						glColor3f(1.0f, 1.0f, 1.0f);													  if (num_100){							  glRasterPos2f(x-2.5,y); 							  glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + num_100);						  }							  else {							  glRasterPos2f(x-2.5,y); 							  glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);						  }						  if (num_10){							  glRasterPos2f(x,y); 							  glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + num_10);						  }						  else{							  glRasterPos2f(x,y); 							  glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);						  }						  glRasterPos2f(x+2.5,y);  						  glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + num_1);								}				}						numb = 0;				num_1 = 0;				num_10 = 0;				num_100 = 0;				glEnd();			}			if (LegendFlag == true) {				int numb_1, numb_10, numb_100, numb_1000, numb_10000, numb_100000, numb_1000000, numb_10000000, in;					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 8);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 43, (gridspace * n)/2-(gridspace/2) - 8);					glEnd();					in = inpres * 1000 * 12/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 8);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 8);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 8);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 8);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 8);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 8);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 8);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 8);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 8); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 8);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 8); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 8);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 8);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 8);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(1.000f, 0.000f, 0.000f);	//Red				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 8);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 8);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 16);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 16);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 16);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 41, (gridspace * n)/2-(gridspace/2) - 16);					glEnd();					in = inpres * 1000 * 11/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 16);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 16);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 16);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 16);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 16);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 16);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 16);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 16);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 16); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 16);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 16); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 16);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 16);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 16);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(1.000f, 0.500f, 0.000f);	//Orange Red				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 16);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 16);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 24);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 24);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 24);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 43, (gridspace * n)/2-(gridspace/2) - 24);					glEnd();					in = inpres * 1000 * 10/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 24);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 24);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 24);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 24);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 24);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 24);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 24);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 24);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 24); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 24);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 24); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 24);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 24);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 24);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(1.000f, 0.800f, 0.000f);	//Coral				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 24);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 24);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 32);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 32);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 32);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 41, (gridspace * n)/2-(gridspace/2) - 32);					glEnd();					in = inpres * 1000 * 9/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 32);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 32);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 32);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 32);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 32);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 32);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 32);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 32);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 32); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 32);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 32); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 32);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 32);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 32);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(1.000f, 1.000f, 0.000f);	//Yellow				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 32);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 32);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 40);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 40);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 40);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 43, (gridspace * n)/2-(gridspace/2) - 40);					glEnd();					in = inpres * 1000 * 8/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 40);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 40);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 40);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 40);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 40);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 40);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 40);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 40);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 40); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 40);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 40); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 40);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 40);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 40);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(0.800f, 0.900f, 0.000);	//Medium Spring Green				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 40);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 40);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 48);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 48);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 48);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 41, (gridspace * n)/2-(gridspace/2) - 48);					glEnd();					in = inpres * 1000 * 7/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 48);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 48);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 48);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 48);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 48);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 48);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 48);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 48);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 48); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 48);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 48); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 48);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 48);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 48);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(0.5f, 0.9f, 0.0f);	//Green				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 48);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 48);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 56);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 56);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 56);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 43, (gridspace * n)/2-(gridspace/2) - 56);					glEnd();					in = inpres * 1000 * 6/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 56);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 56);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 56);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 56);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 56);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 56);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 56);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 56);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 56); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 56);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 56); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 56);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 56);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 56);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(0.000f, 1.000f, 0.000f);	//Lime Green				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 56);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 56);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 64);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 64);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 64);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 41, (gridspace * n)/2-(gridspace/2) - 64);					glEnd();					in = inpres * 1000 * 5/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 64);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 64);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 64);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 64);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 64);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 64);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 64);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 64);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 64); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 64);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 64); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 64);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 64);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 64);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(0.000f, 1.000f, 0.498f);	//Spring Green				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 64);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 64);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 72);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 72);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 72);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 43, (gridspace * n)/2-(gridspace/2) - 72);					glEnd();					in = inpres * 1000 * 4/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 72);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 72);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 72);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 72);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 72);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 72);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 72);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 72);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 72); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 72);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 72); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 72);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 72);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 72);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(0.0f, 1.0f, 1.0f);	//Aquamarine				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 72);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 72);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 80);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 80);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 80);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 41, (gridspace * n)/2-(gridspace/2) - 80);					glEnd();					in = inpres * 1000 * 3/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 80);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 80);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 80);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 80);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 80);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 80);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 80);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 80);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 80); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 80);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 80); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 80);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 80);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 80);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(0.0f, 0.8f, 1.0f);	//Medium Torquoise				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 80);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 80);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 88);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 88);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 88);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 43, (gridspace * n)/2-(gridspace/2) - 88);					glEnd();					in = inpres * 1000 * 2/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 88);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 88);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 88);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 88);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 88);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 88);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 88);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 88);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 88); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 88);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 88); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 88);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 88);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 88);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(0.0f, 0.5000f, 1.000f);	//Sky Blue				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 88);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 88);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 96);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 96);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 96);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 41, (gridspace * n)/2-(gridspace/2) - 96);					glEnd();					in = inpres * 1000 * 1/12;					numb_1 = in % 10; 					numb_10 = (in  / 10) % 10; 					numb_100 = (in  / 100) % 10; 					numb_1000 = (in  / 1000) % 10; 					numb_10000 = (in  / 10000) % 10; 					numb_100000 = (in  / 100000) % 10; 					numb_1000000 = (in  / 1000000) % 10;					if (numb_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 96);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 39, (gridspace * n)/2-(gridspace/2) - 96);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 96);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 36, (gridspace * n)/2-(gridspace/2) - 96);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 96);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 33, (gridspace * n)/2-(gridspace/2) - 96);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 96);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_100);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 30, (gridspace * n)/2-(gridspace/2) - 96);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 96); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 27, (gridspace * n)/2-(gridspace/2) - 96);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (numb_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 96); // Set the position for the second digit. x = leftX |plus| num_1*constant+SizeOfCharacter; y = topY |plus| num_10*constant 						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + numb_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 96);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 96);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 96);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);					glEnd();				glBegin(GL_QUADS);				glColor3f(0.000f, 0.000f, 1.000f);	//Slate Blue				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 96);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 96);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 104);				glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 50, (gridspace * n)/2-(gridspace/2) - 104);				glEnd();					glBegin(GL_LINES);					glLineWidth(0.5);					glColor3f(0.9882f, 0.9882f, 0.9882f);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 45, (gridspace * n)/2-(gridspace/2) - 104);					glVertex2f(- ((gridspace * n)/2-(gridspace/2)) - 43, (gridspace * n)/2-(gridspace/2) - 104);					glEnd();					//0 pa on the screen					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 24, (gridspace * n)/2-(gridspace/2) - 104);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 19, (gridspace * n)/2-(gridspace/2) - 104);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 80);					glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) - 16, (gridspace * n)/2-(gridspace/2) - 104);  					glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 97);


So above bit goes into the
.
.
bunch of stuff
.
.

Thanks!
Immediate mode (glVertex3F and its kin) is very, very slow.
Think about using VBOs to speed up your rendering.

[size=1]Visit my website, rawrrawr.com

I see.
But I have no idea how to implement VBO...
Could you give an example?
Let's say drawing a simple square?
As mentioned above, using intermediate mode is very slow. You might want to try using display lists to speed up the drawing. It makes a huge difference:

http://www.lighthouse3d.com/opengl/displaylists/

Also, calling glutBitmapCharacter for every character is probably very slow. You might want to check out glutBitmapString(). Probably a lot faster.
scottrick49
Writing simulations like this is how I ended up here in the first place, so I feel your pain. I remember authoring some really rotten code while thinking "I just want to see my data" the whole time. So, I'm going to try to help you out.

Now a lot of this isn't going to be the ultimate, best, most super way to do things, but I want to keep it on a level that you can understand based on what you seem to know, hackable in case you want to change it, and where you won't need to become a guru to use it elsewhere.

First things first: You should break your render function into smaller chunks. Not only will it be easier for you to go through and read, but you could use a tool called a profiler to see where the actual slow parts are.

Your text rendering code looks painful to write. A few notes on it:

		glColor3f(1.0f, 1.0f, 1.0f);			//F			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 50,  (gridspace * n)/2-(gridspace/2)+ 5) ;  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 70);			//I			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 53,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 73);			//L			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 56,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 76);			//L			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 59,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 76);			//T			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 65,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 84);			//I			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 68,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 73);			//M			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 71,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 77);			//E			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 74,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 69);			//:			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 77,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 58);			int fill_1, fill_10, fill_100, fill_1000, fill_10000, fill_100000, fill_1000000, fill_10000000;					fill_1 = filltime % 10; 					fill_10 = (filltime  / 10) % 10; 					fill_100 = (filltime  / 100) % 10; 					fill_1000 = (filltime  / 1000) % 10; 					fill_10000 = (filltime  / 10000) % 10; 					fill_100000 = (filltime  / 100000) % 10; 					fill_1000000 = (filltime  / 1000000) % 10;					fill_10000000 = (filltime  / 10000000) % 10;					if (fill_10000000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 80,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_10000000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 80,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_1000000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 83,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_1000000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 83,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_100000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 86,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_100000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 86,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_10000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 89,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_10000);					}						else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 89,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_1000){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 92,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_1000);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 92,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_100){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 95,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_100);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 95,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_10){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 98,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_10);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 98,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}					if (fill_1){						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 101,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48 + fill_1);					}					else {						glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 101,  (gridspace * n)/2-(gridspace/2)+ 5);  						glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 48);					}			//S			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 107,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 83);			//E			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 110,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 69);			//C			glRasterPos2f(- ((gridspace * n)/2-(gridspace/2)) + 113,  (gridspace * n)/2-(gridspace/2)+ 5);  			glutBitmapCharacter(GLUT_BITMAP_9_BY_15 , 67);			glEnd();


1) You don't need to reset the raster position for every character. This is already done in glutBitmapCharacter.
2) glEnd() isn't necessary where there is no glBegin()

But that doesn't matter right now because we're going to scrap the whole thing with a new function:

void render_text(float x, float y, char* s){	glRasterPos2f(x,y);	for ( unsigned int i=0; i < strlen( s ); i++ )		glutBitmapCharacter(GLUT_BITMAP_9_BY_15,s);}


We're going to build the string using snprintf, which is just like printf (which I assume you are familiar with) except that it puts the result into a variable instead of the screen.

// This replaces that whole crazy sectionchar text_buffer[40]; // should be big enoughsnprintf(text_buffer, 40, "FILL TIME %d SEC", filltime );glColor3f(1.0f, 1.0f, 1.0f);int Gc = gridspace*(n-1)/2;render_text( 50-Gc, 5+Gc, text_buffer );


Also, it looks like you used (gridspace * n)/2-(gridspace/2)) everywhere. I just put it in the variable Gc. There's no sense in recalculating it every single time. (I made about 274 replacements, not counting the text section that I just replaced.)

Now, another big cost is glBegin() and glEnd(). These have a big of baggage related to some behind-the-scene changes they make. I wouldn't worry about cutting them out - but try to avoid redundancy. For instance:

		glBegin(GL_LINES);		glColor3f(0.1843f, 0.3098f, 0.1843f);			glVertex3f( - ((gridspace * n)/2-(gridspace/2)), - ((gridspace * n)/2-(gridspace/2)), 0);			glVertex3f( - ((gridspace * n)/2-(gridspace/2)), - ((gridspace * n)/2-(gridspace/2)), -5);			glEnd();		glBegin(GL_LINES);		glColor3f(0.1843f, 0.3098f, 0.1843f);			glVertex3f( - ((gridspace * n)/2-(gridspace/2)), (gridspace * n)/2-(gridspace/2), 0);			glVertex3f( - ((gridspace * n)/2-(gridspace/2)), (gridspace * n)/2-(gridspace/2), -5);			glEnd();		glBegin(GL_LINES);		glColor3f(0.1843f, 0.3098f, 0.1843f);			glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), - ((gridspace * n)/2-(gridspace/2)), 0);			glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), - ((gridspace * n)/2-(gridspace/2)), -5);			glEnd();		glBegin(GL_LINES);		glColor3f(0.1843f, 0.3098f, 0.1843f);			glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), 0);			glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), -5);			glEnd();


GL_LINES tells OpenGL that you are going to give it a set of vertexes, and that it should take them in pairs and make line segments out of them. Therefore, you can change sections like this to:

		glBegin(GL_LINES);		glColor3f(0.1843f, 0.3098f, 0.1843f);		glVertex3f( - ((gridspace * n)/2-(gridspace/2)), - ((gridspace * n)/2-(gridspace/2)), 0);		glVertex3f( - ((gridspace * n)/2-(gridspace/2)), - ((gridspace * n)/2-(gridspace/2)), -5);			glColor3f(0.1843f, 0.3098f, 0.1843f);		glVertex3f( - ((gridspace * n)/2-(gridspace/2)), (gridspace * n)/2-(gridspace/2), 0);		glVertex3f( - ((gridspace * n)/2-(gridspace/2)), (gridspace * n)/2-(gridspace/2), -5);			glColor3f(0.1843f, 0.3098f, 0.1843f);		glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), - ((gridspace * n)/2-(gridspace/2)), 0);		glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), - ((gridspace * n)/2-(gridspace/2)), -5);			glColor3f(0.1843f, 0.3098f, 0.1843f);		glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), 0);		glVertex3f(- ((gridspace * n)/2-(gridspace/2)) + gridspace*(m-1), (gridspace * n)/2-(gridspace/2), -5);			glEnd();


And reduce a lot of internal state switching.

And the last thing (for now) is that you are drawing a lot of geometry (circles, squares, grids) the hard way every single frame. Instead of something like:

glBegin(GL_TRIANGLE_FAN);for (k=0; k<=360; k+=5) {	glVertex2f( (-(gridspace * n)/2-(gridspace/2)+j*gridspace) + sin(k) * 3.5, ( ((gridspace * n)/2-(gridspace/2) - (i*gridspace)) + cos(k) * 3.5) );}glEnd();


It would be better to make that its own function, taking arguments for position and radius.

  void draw_circle( float x, float y, float r ) {  glBegin(GL_TRIANGLE_FAN);    for (k=0; k<=360; k+=15)      glVertex2f( x + sin(k*0.0174) * r, y + cos(k*0.0174) * r );  glEnd();}


(sin() and cos() takes radians as an argument, not degrees. Also, I don't think you need 72 triangles to make a circle look nice.)

But even better than that, would be to build a display list. This tells OpenGL "I'm going to draw this same thing over and over again, so don't make me explain it every time." It really speeds things up.

// this can be a globalGLuint circle;// This section gets run once, before you ever render// Tells GL we are creating a new listglNewList( circle, GL_COMPILE );  glBegin(GL_TRIANGLE_FAN);    for (k=0; k<=360; k+=15)      glVertex2f( sin(k*0.0174) * 3.5, cos(k*0.0174) * 3.5 );  glEnd();glEndList();// This part goes wherever you would render the circleglPushMatrix();glTranslatef( x, y );glColor3f( r, g, b );glCallList( circle );glPopMatrix();


Try to implement my suggestions, and if you have any questions I'll be lurking. I'll probably also have more to say after poking around a little more :)

[Edited by - erissian on March 7, 2009 8:51:57 PM]
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
Ahhhh finally a helpful reply!
Can't wait to try these out!
Thanks and I'll let you know asap!
Alright, only ONE error!

Text rendering bit.
snprintf: identifier not found

Let me know what I should do.
Thanks again!

[Edited by - pkiskool on March 5, 2009 3:39:29 PM]
Not to be mean, but come on. Click on the snprintf function in the code and hit f1 for help. It will tell you what header to include, solved.

As for the "glTransform" issue, I'll let you help yourself and give you a link to the OpenGL blue book (reference). From there you should be able to figure out the solution.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

This topic is closed to new replies.

Advertisement