 /*
* Code by John Brosz for CPSC 453 Lab #3
* Derived from lab2_cube.c, a OpenGL Red Book example
*/

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

void init(void) 
{
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glLineWidth(3.0f);
}

void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   // draw a square
   glBegin(GL_LINE_LOOP);
     glColor3f(1.0, 1.0, 1.0);
     glVertex2f(-.5,.5); // vertex2f sets z=0
     glColor3f(0, 1, 0);
     glVertex2f(.5,.5);
     glColor3f(0, 0, 1);
     glVertex2f(.5,-.5);
     glColor3f(1, 0, 0);
     glVertex2f(-.5,-.5);
   glEnd();
   glFlush ();
}

void reshape (int w, int h)
{
   glViewport(0, 0, (GLsizei) w, (GLsizei) h); 
   // switch matrix mode so we can change the projection matrix
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity(); // load identity so we don't 'compound change' the projection matrix
   glOrtho(-1,1,-1,1,-1,1); // mult in an orthographic matrix
   glMatrixMode(GL_MODELVIEW); // reseting to model view matrix mode so we don't go crazy
}

void keyboard(unsigned char key, int x, int y)
{
   switch (key) {
      case 27:
         exit(0); // returning 0 is code for everything exited normally
         break;
   }
}

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize(500, 500); 
   glutInitWindowPosition (100, 100);
   glutCreateWindow(argv[0]);
   init();
   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutKeyboardFunc(keyboard);
   glutMainLoop();
   return 0;
}


