#include  

#include  
#include 
#include 

float	mouseX = 0;
float	mouseY = 0;
int		windowW = 800;
int		windowH = 600;

#define PI 3.14159265358979


void displayFunc ( void )
{
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //clear buffer
	
	glColor3f( 1,0,0 );
	//draws rectangle using 2 points that are opposite vertices
	//derivng vertices from mouse location
	glRectf( mouseX-5, mouseY-5, mouseX+5, mouseY+5 );
	
	// place your drawing code here
	
	
	glutPostRedisplay(); //marks current window needs to be redisplayed
	glutSwapBuffers();   //swap buffer of current window
}


void reshapeFunc ( int w, int h )
{
	windowW = w;
	windowH = h;

	glViewport( 0, 0, w, h );
	glMatrixMode( GL_PROJECTION ); //set matrix mode
	glLoadIdentity(); //replace the current matrix with the identity matrix 
	gluOrtho2D( 0,w,0,h ); //define a 2D orthographic projection matrix

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
}

//mouse down callback function
void mouseDownFunc ( int button, int state, int x, int y )
{   
	mouseX = x;
	mouseY = windowH - y;
}

//mouse move/passive callback function
void mouseMoveFunc ( int x, int y )
{
	mouseX = x;
	mouseY = windowH - y;
}

//mouse drag/ motion callback function
void mouseDragFunc ( int x, int y )
{
	mouseX = x;
	mouseY = windowH - y;
}

//keypboard callback function
void keyboardFunc ( unsigned char key, int x, int y )
{
}

//special function callback function
void arrowKeyFunc ( int a_keys, int x, int y )
{
}


void init ( GLvoid )
{
	glShadeModel( GL_SMOOTH ); //specify shading technique
	//specifies the red, green, blue, and alpha values used 
    //by glClear to clear the color buffers
	glClearColor( 1.0, 1.0, 1.0, 1.0 );
	glEnable ( GL_COLOR_MATERIAL ); //enable material paramters to track the current color
	glEnable( GL_BLEND ); //blend the incoming RGBA color values with the values in the color buffers
	//specifies how source and destination RGBA blending factors are computed
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}


int main ( int argc, char** argv )
{
	glutInit( &argc, argv );// initialize the GLUT library and start session 
	
	glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE ); //set initial displa mode
	glutInitWindowSize( windowW, windowH ); //initialize window size
	glutCreateWindow( "CompFormApp" ); //create GUI with the following name
	//set callback functions for current window...
	glutDisplayFunc( displayFunc ); //sets display callback function
	glutReshapeFunc( reshapeFunc ); //sets reshape callback function
	glutMouseFunc( mouseDownFunc ); //sets mouse callback function
	glutMotionFunc( mouseDragFunc ); //sets motion callback function (when mouse is pressed & moving, i.e drag)
	glutPassiveMotionFunc( mouseMoveFunc ); //sets passive callback function (when mouse is moving, but not pressed)
	glutKeyboardFunc( keyboardFunc ); //set keyboard callback function
	glutSpecialFunc( arrowKeyFunc ); //sets a special keyboard function/directional key press callback
	init();
	
	//GLUT event processing loop. 
    //calls all registered callback functions
	glutMainLoop( );
  
	return 0;
}