#include <unistd.h>
float offset = 0;

void createGLUTMenus(void) {
	int menu;
	menu = glutCreateMenu(processMenuEvents);
	glutAddMenuEntry("Restart",RESTART);
	glutAddMenuEntry("Pause",PAUSED);
	glutAddMenuEntry("Exit",EXIT);
	glutAttachMenu(GLUT_RIGHT_BUTTON);
}

void processMenuEvents(int option) {
	switch (option) {
		case RESTART :
			offset++;
			break;
		case PAUSED :
			offset--;
			break;
		case EXIT :
			exit(0);
			break;
	}
	printf("offset: %f\n", offset);
}

static void Animate(void){
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//GLfloat vertices1[4];
	//sides, vertices, coordinates
	int s, v, c;


	GLfloat vertices[8][4];
/*
	for(s=0; s<6; s++;){

		vertices[s][0][0] = -
		vertices[s][0][1] =
		vertices[s][0][2] =

		vertices[s][1][0] =
		vertices[s][1][1] =
		vertices[s][1][2] =

		vertices[s][2][0] =
		vertices[s][2][1] =
		vertices[s][2][2] =

		vertices[s][3][0] =
		vertices[s][3][1] =
		vertices[s][3][2] =

	}



	for(s=0; s<6; s++;){
		for(v=0; v<4; v++;){
			for(c=0; c<3; c++;){
				vertices[s][v][c]=
			}
		}
	}


	vertices[0] = {-4.0, -4.0, 4.0, offset};
	vertices[1] = {-4.0,  4.0, 4.0, offset};
	vertices[2] = { 4.0, 4.0, 4.0, offset};
	vertices[3] = { 4.0,  -4.0, 4.0, offset};

	vertices[4] = {-4.0, -4.0, 0.0, offset};
	vertices[5] = {-4.0,  4.0, 0.0, offset};
	vertices[6] = { 4.0,  4.0, 0.0, offset};
	vertices[7] = { 4.0, -4.0, 0.0, offset};
-4.000000, -4.000000, 4.000000, 0.000000
-4.000000, -4.000000, 4.000000, 0.000000
4.000000, -4.000000, 4.000000, 0.000000
4.000000, -4.000000, 4.000000, 0.000000
-4.000000, -4.000000, 0.000000, 0.000000
-4.000000, -4.000000, 0.000000, 0.000000
4.000000, -4.000000, 0.000000, 0.000000
4.000000, -4.000000, 0.000000, 0.000000


*/
//sleep(1);
	v=1;
	c=-1;
	for(s=0; s<8; s++){
		//vertices[s][0] = -1*v*c;
		if(s % 2 == 0){
			v *= -1;
		}
		vertices[s][0] = v*4;
		if((s+1) % 2 == 0){
			c *= -1;
		}
		//	v = 1;
		//}
		vertices[s][1] = c*4;
		//vertices[s][1] = v*c;

		if(s>3){
			vertices[s][2] = 0;
		}else{
			vertices[s][2] = 4;
		}
		vertices[s][3] = offset;
		//v*=-1;
		//printf("%f, %f, %f, %f\n", vertices[s][0], vertices[s][1], vertices[s][2], vertices[s][3]);
	}
	



	glLoadIdentity();

	glTranslatef ( 0, 0, -25 );

	glColor3f( 1.0, 1.0, 0.0 );


/*
	glRectf(-0.50f,2.00f, 0.50f, -2.00f);

	glLoadIdentity();
	glTranslatef ( 0, 0, -25 );
	glColor3f( 1.0, 1.0, 0.0 );
*/

	//glRotatef(22.5, 0, 0, 2);
	//glRotatef(45, 0, 2, 0);
	//glRotatef(45, 2, 0, 0);
	//glRotatef(45, -4, -4, 4);
	//glTranslatef(2, 2, 2);

	glBegin( GL_POLYGON );

	glVertex4fv((const GLfloat *)&vertices[0]);
	glVertex4fv((const GLfloat *)&vertices[1]);
	glVertex4fv((const GLfloat *)&vertices[2]);
	glVertex4fv((const GLfloat *)&vertices[3]);

	glVertex4fv((const GLfloat *)&vertices[4]);
	glVertex4fv((const GLfloat *)&vertices[5]);
	glVertex4fv((const GLfloat *)&vertices[6]);
	glVertex4fv((const GLfloat *)&vertices[7]);

	glEnd();	


//	glutSolidCube(20.0); 


	glFlush();	
	glutSwapBuffers();
	glutPostRedisplay();
}


void OpenGLInit(void){
	glShadeModel( GL_FLAT );
	glClearColor( 0.0, 0.0, 0.0, 0.0 );
	glClearDepth( 50.0 );
	glEnable( GL_DEPTH_TEST );

}

static void ResizeWindow(int w, int h){
	float aspectRatio;
	h = (h == 0) ? 1 : h;
	w = (w == 0) ? 1 : w;
	glViewport( 0, 0, w, h );
	aspectRatio = (float)w/(float)h;
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluPerspective( 70.0, aspectRatio, 10.0, 30.0 );
	glMatrixMode( GL_MODELVIEW );
}
