#ifdef _WIN32
/*This is windows specific*/
#include <windows.h> 
#endif

#ifdef __APPLE__
/*OpenGL includes for Mac OS X*/
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
/*OpenGL includes for other OS's*/
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif

#include <math.h>

int width,height;
int markx,marky;
int markx2,marky2;
int b_left;

void myInit(void)
{
	glClearColor(0,0,0,0);
	glColor3f(1,1,1);
	glPointSize(1);

	markx=320;marky=120;
	markx2=320;marky2=240;
}

void myReshape(int w,int h)
{
	width=w;
	height=h;
}

void myDisplay(void)
{
	int x,y;

	glViewport(0,0,(GLsizei)width,(GLsizei)height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0,(GLsizei)width,(GLsizei)height,0);

	glDrawBuffer(GL_BACK);
	glClear(GL_COLOR_BUFFER_BIT);
	 
	glBegin(GL_POINTS);
		for(y=0;y<height;y++) 
		{
			for(x=0;x<width;x++) 
			{
				double xf=((double)x)/((double)width);
				double yf=((double)y)/((double)height);
				glColor3f(xf,yf,0); 
				if(x!=markx && y!=marky)glVertex2i(x,y);
			}
		}
	glEnd();

	glPointSize(100);

	glBegin(GL_POINTS);
	/*First square*/
	glColor3f(1,1,0);
	glVertex2i((GLsizei)markx,(GLsizei)marky);
	/*Second square*/
	glColor3f(0,1,1);
	glVertex2i((GLsizei)markx2,(GLsizei)marky2);
	glEnd();

	glPointSize(1);

	glFlush();
	glFinish();
	glutSwapBuffers();
}

void myMouse(int button,int state,int x,int y)
{
	if(button==GLUT_LEFT_BUTTON)
	{
		b_left=1;
	}
	else
	{
		b_left=0;
	}
}

void myMovedMouse(int x,int y)
{
	if(b_left)
	{
		markx=x;marky=y;
	}
	else
	{
		markx2=x;marky2=y;
	}
	myDisplay();
}

void myKeyboard(unsigned char key,int x,int y)
{
	markx2+=10;
	myDisplay();
}

int main(int argc,char **argv)
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
	glutInitWindowSize(640,480);
	glutInitWindowPosition(100,150);
	glutCreateWindow("Hello World");
	glutDisplayFunc(myDisplay);
	
	glutReshapeFunc(myReshape);
	glutMouseFunc(myMouse);
	glutMotionFunc(myMovedMouse);
	glutKeyboardFunc(myKeyboard);
	
	myInit();
	glutMainLoop();
	return(1);
}

