//
// The main modules for cs4731
//   Copyright (C) 1999,2000  Mark R. Stevens
//
//   This program is free software; you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation; either version 2 of the License, or
//   (at your option) any later version.
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program; if not, write to the Free Software
//   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// 
// Additional Modifications for windows port
//     Paul Tessier<phernost@wpi.edu>
//     Stephen Laverty <steve@WPI.EDU>

// C includes
#include <math.h>

// C++ includes
#include <iostream>
#include <string.h>

using namespace std;

#ifdef WIN32                     
#include <process.h>
#include <string.h>
#endif

// The local includes
#include "minigl.h"
#include "miniglut.h"

// a specific implementation of opengl
#include "openGL.h"
#include "cs4731GL.h"

// the applications
#include "gears.h"
#include "bounce.h"
#include "evil.h"
#include "stars.h"
#include "hill_house.h"


//-----------------------------------------------------------------------------
int main(int argc, char *argv[]) {

  // create the specific opengl implementation: this will eventually
  // be your derived class
  minigl *mgl = static_cast<minigl *>(0);
  
  // the requested app
  cs4731app *app = static_cast<cs4731app *>(0);

  // hack for vc++
  int i = 0;

  // check the command line arguments to determine which type off app to run
  for (i = 1; i < argc; i++) {
    if       (strcmp(argv[i], "-gears" ) == 0)  app = new gears();
    else if  (strcmp(argv[i], "-bounce") == 0)  app = new bounce();
    else if  (strcmp(argv[i], "-stars" ) == 0)  app = new stars();
    else if  (strcmp(argv[i], "-evil"  ) == 0)  app = new evil();
    else if  (strcmp(argv[i], "-house"  ) == 0)  app = new hill_house();
  }

  // check the command line for the type of opengl to run
  for (i = 1; i < argc; i++) {
    if       (strcmp(argv[i], "-openGL" )  == 0) mgl = new openGL();
    else if  (strcmp(argv[i], "-cs4731GL") == 0) mgl = new cs4731GL();
  }

  // if no apps were specified exit
  if ((app == static_cast<cs4731app *>(0)) || 
      (mgl == static_cast<minigl    *>(0))) {
    cerr << "\ncs4731 -glimp -app:\n";
    cerr << "\tWhere app is:\n";
    cerr << "\t\t-gears\t\trun gears demo\n";
    cerr << "\t\t-bounce\t\trun bounce demo\n";
    cerr << "\t\t-stars\t\trun stars demo\n";
    cerr << "\t\t-evil\t\trun evil demo\n";
    cerr << "\t\t-house\t\trun the house scene from chapter 5 of Hill\n";
    cerr << "\tWhere glimp is:\n";
    cerr << "\t\t-openGL\t\trun code using true openGL\n";
    cerr << "\t\t-cs4731GL\trun code using your openGL\n";
    std::exit(0);
  }

  // This is the creation of the miniglut interface
  miniglut mglut(mgl, app, argc, argv);

  // initialize the appropriate cs4731app
  app->init(*mgl, mglut);

  // output the usage
  app->usage();

  // enter the event loop
  mglut.mglutMainLoop();

  // return success
  return true;

}
//-----------------------------------------------------------------------------





