#include <iostream>



#ifdef __APPLE__
#include <GLUT/glut.h>  //apple include line
#else
#include <GL/glut.h> //linux and windows include line
#endif

using namespace std;
int winheight=500, winwidth=500;
float xs,ys, xe,ye;
float theta;

void display();
void init();
void keyboard(unsigned char key, int x, int y);
void mouse(int button, int state, int x, int y);
void reshape(int,int);
void idle();


void passivemotion(int x, int y);

int main(int argc, char *argv[])
{
  glutInit(&argc, argv);
  init();
  glutMainLoop();
}



//the initialization function
void init()
{
  //  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  glutInitWindowSize(winwidth,winheight);
  glutInitWindowPosition(0,0);
  glutCreateWindow("Ramsey");
  glutDisplayFunc(display);
  glutKeyboardFunc(keyboard);
  glutMouseFunc(mouse);
  glutIdleFunc(idle);
  glutPassiveMotionFunc(passivemotion);
  glutReshapeFunc(reshape);

  //clear to black and fill to "greenish"
  glClearColor(0.0,0.0,0.0,0.0);
  glColor3f(0.1,1.0,0.1);


  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  //to setup standard orthogonal view with clipping box as cube of side 2
  //with center at the origin. This is the default view  (uncomment below)
  //  gluOrtho2D(-2.0,2.0,-2.0,2.0);

  //the following sets up the screen as winwidth x winheight pixels

  gluOrtho2D(0,winwidth,0,winheight);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

}




void reshape(int w, int h)
{
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  //  if(w <= h)
  //    gluOrtho2D(-2.0,2.0,-2.0*h/w, 2.0f* h/w);
  //  else
  //    gluOrtho2D(-2.0 * w / h, 2.0 * w / h, -2.0, 2.0);
  gluOrtho2D(0,w,0,h);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glViewport(0,0,w,h);
  winheight = h;
  winwidth = w;
}

//text?

void text(char *s, float x, float y)
{
  glRasterPos2d(x,y);
  int i = 0;
  for (;i < strlen(s); i++)
    {      
      glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,s[i]);
      
    }
}





//the display function
//whatever is in here is what will be displayed
#define NUM_PTS 100.0
void display()
{

  glClear(GL_COLOR_BUFFER_BIT);
  for(int i = 0; i < NUM_PTS; i ++)
    {
      glBegin(GL_POINTS);
        glColor3f(i/NUM_PTS,i/NUM_PTS,i/NUM_PTS);
	glVertex2f(400,200+250*i/(double)NUM_PTS);
      glEnd();
    }
  glBegin(GL_LINES);
  glColor3f(1,1,1);
  glVertex2f(350,450);
  glColor3f(0,0,0);
  glVertex2f(350,200);
  glEnd();

  glColor3f(1,1,0);
  text("Hello, Are We Having Fun Yet?", 2,2 );
  glColor3f(0,1,1);
  text("Hooooray", 50,50);
  glutSwapBuffers();//double buffer only
}


//the keyboard function
void keyboard(unsigned char key, int x, int y)
{
  if(key == 'q' || key == 'Q' || key == 3) //q or escape
    exit(0);
  if(key =='p')
    printf("(%d,%d)\n",x,winheight-y);
}


//the mouse does stuff
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN  && button == GLUT_RIGHT_BUTTON)
      exit(0);
    else if(state==GLUT_DOWN)
      {
	printf("(%d,%d)\n",x,winheight-y);
	glutPostRedisplay();
      }
}



void passivemotion(int x, int y)
{

}


void idle() 
{ 
}
