#include <GL/glut.h>
#include <iostream>

using namespace std;

float winWid,winHeight;
float rx,ry;

void redraw( void )
{
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.00,1.00,0.0);
	glRectf(100.0,100.0,300.0,200.0);
	glColor3f(1.0,0.0,0.0);

	glRectf(rx,ry,100.0+rx,20.0+ry);

	glutSwapBuffers();
}


void motion(int x, int y) 
// called when a mouse is in motion with a button down
{
 	rx = x; ry = winHeight - y;
}


void mousebutton(int button, int state, int x, int y)
{
	if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)

	{
		rx = x; ry = winHeight - y;
	}
}

void keyboard(unsigned char key, int x, int y) 
// x and y givethe mouse pos
{
	cerr << "Key " << key << " " << int(key) << "\n";
}

int main(int argc, char *argv[])
{
	cerr << "hello world\n";

	winWid = 600.0;
	winHeight = 400.0;

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
	glutCreateWindow("Basic example");
	glutPositionWindow(200,100);
	glutReshapeWindow(winWid,winHeight);

	glClearColor(0.0,0.0,0.0,1.0);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0,winWid,0.0,winHeight, -100.0, 100.0);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glutDisplayFunc(redraw);
	glutIdleFunc(redraw);
	glutMotionFunc( motion);	
	glutMouseFunc( mousebutton);
	glutKeyboardFunc( keyboard );
	glutMainLoop();

	return 0;
}