#include <gl\glut.h>
#include <iostream.h>

int firstWindow, secondWindow;

float xRotation = 0.0;
float yRotation = 0.0;

void displayFirstWindow (void) 
{
	glClear(GL_COLOR_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glRotatef(xRotation, 0.0, 0.5, -1.0);
	glutWireCube(1.0);
	glutSwapBuffers();
}

void displaySecondWindow (void) 
{
	glClear(GL_COLOR_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glRotatef(yRotation, 0.0, 0.5, 1.0);
	glutWireCube(1.0);
	glutSwapBuffers();
}

void keyboard (unsigned char key, int x, int y) 
{
	switch (key) 
   {
	case '1':
		glutSetWindow(firstWindow);
		break;
	case '2':
		glutSetWindow(secondWindow);
		break;
	case 27:
		exit(0);
	}
}

void spin () 
{
	static int currentWindow;
	int newWindow = glutGetWindow();
	if (newWindow != currentWindow) {
		currentWindow = newWindow;
		cout << "Window " << currentWindow << endl;
	}
	xRotation += 1.0;
	yRotation += 2.0;
	glutPostRedisplay();
}

int main (int argc, char *argv[]) 
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

	glutInitWindowSize(300, 300);
	glutInitWindowPosition(100, 100);
	firstWindow = glutCreateWindow("Window 1");
	glutDisplayFunc(displayFirstWindow);
	glutKeyboardFunc(keyboard);

	glutInitWindowSize(200, 200);
	glutInitWindowPosition(100, 500);
	secondWindow = glutCreateWindow("Window 2");
	glutDisplayFunc(displaySecondWindow);
	glutKeyboardFunc(keyboard);

	glutIdleFunc(spin);
	glutMainLoop();
	return 0;
}

