#include "TriangleMesh.h"
#include "Sphere.h"
#include "Canvas.h"

#include <GL/glut.h>

using namespace columbia;

int main_window;

void init(void)
{    
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel(GL_SMOOTH);
   glEnable(GL_DEPTH_TEST);
}


void display(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glTranslatef(0,0,-2);
  
  glBegin(GL_TRIANGLES);
  {    
    glVertex3f( -1,  0, 0 );
    glVertex3f(  1,  0, 0 );
    glVertex3f(  0,  1, 0 );
  }
  glEnd();

  glutSwapBuffers();
}


void reshape(int w, int h)
{
  glViewport(0, 0, (GLsizei) w, (GLsizei) h);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(70.0, (GLfloat) w/(GLfloat) h, .5, 30.0);
}


void myGlutIdle( void )
{
  /* According to the GLUT specification, the current window is 
     undefined during an idle callback.  So we need to explicitly change
     it if necessary */
  if ( glutGetWindow() != main_window ) 
    glutSetWindow(main_window);  

  glutPostRedisplay();
}



int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
   glutInitWindowSize(250, 250);
   glutInitWindowPosition(100, 100);
   main_window = glutCreateWindow(argv[0]);

   init();

   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutIdleFunc( myGlutIdle );
 
   glutMainLoop();
   return 0; 
}

