//   A derived class implementing minigl using openGL
//   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.  
//
//   CS4731: The goal is to derive a class from this base class and
//   implement different components throughout the course.
//
// Additional Modifications for windows port
//     Stephen Laverty <steve@WPI.EDU>
//      Jesse Carney Johnson <penguin@WPI.EDU>
//

// local includes
#include "openGL.h"

#ifdef WIN32                     

// Stephen Laverty <steve@WPI.EDU>
#include <windows.h>
#include <wingdi.h>

#endif

// the real OpenGL implmentation
#ifdef __APPLE_CC__
#include <gl.h>
#include <glu.h>
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif

//-----------------------------------------------------------------------------
openGL::openGL() {

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

//-----------------------------------------------------------------------------
openGL::~openGL() {

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

//-----------------------------------------------------------------------------
void openGL::mglShadeModel(MGLenum mode) {

  // call the real OpenGL function.
  glShadeModel((GLenum) mode);

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

//-----------------------------------------------------------------------------
void openGL::mglBegin(MGLenum mode) {

  // call the real OpenGL function.
  glBegin((GLenum) mode);

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

//-----------------------------------------------------------------------------
void openGL::mglEnd  () {

  // call the real OpenGL function.
  glEnd();

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

//-----------------------------------------------------------------------------
void openGL::mglClear(unsigned int type) {

  // call the real OpenGL function.
  glClear(type);

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

//-----------------------------------------------------------------------------
void openGL::mglClearColor(float r, float g, float b, float a) {

  // call the real OpenGL function.
  glClearColor(r, g, b, a);

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

//-----------------------------------------------------------------------------
void openGL::mglNormal3f(float nx, float ny, float nz) {

  // call the real OpenGL function.
  glNormal3f(nx, ny, nz);

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

//-----------------------------------------------------------------------------
void openGL::mglFinish() {

  // call the real OpenGL function.
  glFinish();

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

//-----------------------------------------------------------------------------
void openGL::mglVertex3f(float x, float y, float z) {

  // call the real OpenGL function.
  glVertex3f(x, y, z);

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

//-----------------------------------------------------------------------------
void openGL::mglPushMatrix() {

  // call the real OpenGL function.
  glPushMatrix();

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

//-----------------------------------------------------------------------------
void openGL::mglPopMatrix () {

  // call the real OpenGL function.
  glPopMatrix();

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

//-----------------------------------------------------------------------------
void openGL::mglRotatef(float angle, float x, float y, float z) {

  // call the real OpenGL function.
  glRotatef(angle, x, y, z);

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

//-----------------------------------------------------------------------------
void openGL::mglTranslatef(float x, float y, float z) {


  // call the real OpenGL function.
  glTranslatef(x, y, z);

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

//-----------------------------------------------------------------------------
void openGL::mglScalef(float x, float y, float z) {


  // call the real OpenGL function.
  glScalef(x, y, z);

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

//-----------------------------------------------------------------------------
void openGL::mglColor3f(float r, float g, float b) {

  // call the real OpenGL function.
  glColor3f(r, g, b);

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

//-----------------------------------------------------------------------------
void openGL::mglMaterialf(MGLenum type, 
			  MGLenum pname, 
			  float red, 
			  float green, 
			  float blue, 
			  float alpha) {

  // store the color
  float color[4] = {red, green, blue, alpha};

  // call the real OpenGL function.
  glMaterialfv((GLenum) type, (GLenum) pname, color);

}

  // Specifies which face being updated.  Must be one of MGL_FRONT,
  // MGL_BACK, or MGL_FRONT_AND_BACK.  pname Specifies the single-valued
  // material parameter of the face or faces that is being updated.
  // Must be MGL_SHININESS.  param Specifies the value that parameter
  // MGL_SHININESS will be set to.
void openGL::mglMaterialfv(MGLenum type, 
			    MGLenum pname, 
				float components[]){
  // call the real OpenGL function.
  glMaterialfv((GLenum) type, (GLenum) pname, components);
}

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
void openGL::mglViewport(int x, int y, int width, int height) {

  // call the real OpenGL function.
  glViewport(x, y, width, height);

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

//-----------------------------------------------------------------------------
void openGL::mglMatrixMode(MGLenum type) {

  // call the real OpenGL function.
  glMatrixMode((GLenum) type);

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

//-----------------------------------------------------------------------------
void openGL::mglLoadIdentity() {

  // call the real OpenGL function.
  glLoadIdentity();

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

//-----------------------------------------------------------------------------
void openGL::mglFrustum(float left, 
			float right, 
			float bottom, 
			float top, 
			float zNear, 
			float zFar) {

  // call the real OpenGL function.
  glFrustum(left, right, bottom, top, zNear, zFar);

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

//-----------------------------------------------------------------------------
void openGL::mglOrtho  (float left,
			float right,
			float bottom,
			float top, 
			float zNear, 
			float zFar) {

  // call the real OpenGL function.
  glOrtho(left, right, bottom, top, zNear, zFar);
  
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
void openGL::mglEnable (MGLenum    cap) {

  // call the real OpenGL function.
  glEnable((GLenum) cap);

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

//-----------------------------------------------------------------------------
void openGL::mglDisable(MGLenum cap) {

  // call the real OpenGL function.
  glDisable((GLenum) cap);

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

//-----------------------------------------------------------------------------
void openGL::mglCullFace(MGLenum type) {

  // call the real OpenGL function.
  glCullFace((GLenum) type);

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

//-----------------------------------------------------------------------------
void openGL::mglLightf(MGLenum num, 
		       MGLenum pname, 
		       float x, 
		       float y, 
		       float z, 
		       float w) {

  // light parameters
  float lp[4] = {x, y, z, w};

  // call the real OpenGL function.
  glLightfv((GLenum) num, (GLenum)pname, lp);

}


  // Set light source parameters.  light Specifies a light.  The
  // number of lights depends on the implementation, but at least
  // eight lights are supported.  They are identified by symbolic
  // names of the form GL_LIGHTi where 0 < i < GL_MAX_LIGHTS.  pname
  // Specifies a single-valued light source parameter for light.
  // GL_SPOT_EXPONENT, GL_SPOT_CUTOFF, GL_CONSTANT_ATTENUATION,
  // GL_LINEAR_ATTENUATION, and GL_QUADRATIC_ATTENUATION are accepted.
  // param Specifies the value that parameter pname of light source
  // light will be set to.
void openGL::mglLightfv(MGLenum num, 
			 MGLenum pname, 
			 float components[ ]){
	// call the real OpenGL function.
	glLightfv((GLenum) num, (GLenum)pname, components);
  }

//-----------------------------------------------------------------------------
void openGL::mglPointSize(float size) {

  // call the real OpenGL function.
  glPointSize(size);

}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void openGL::mglOrtho2D(float w, float x, float y, float z) {

  // call the real OpenGL function.
  gluOrtho2D(w, x, y, z);

}


void openGL::mglVertex2i(int x, int y) {

  // call the real OpenGL function.
  glVertex2i(x, y);

}


void openGL::mglVertex3d(double x, double y, double z){

	// call the real OpenGL function.
	glVertex3d(x, y, z);
}

void openGL::mglTranslated(double x, double y, double z){

	// call the real OpenGL function.
	glTranslated(x, y, z);
}




// wireframe model calls

void openGL::mglutWireCone(double x, double y, double z, double w){
	//call the true glut implementation
	glutWireCone(x, y, (int)z, (int)w);
}

void openGL::mglutWireCube(double side){
	//call the true glut implementation
	glutWireCube(side);
}


void openGL::mglutWireSphere(double x, double y, double z){
	//call the true glut implementation
	glutWireSphere(x, (int)y, (int)z);
}


void openGL::mglutWireTeapot(double size){
	//call the true glut implementation
	glutWireTeapot(size);
}

void openGL::mglutWireTorus(double x, double y, double z, double w){
	//call the true glut implementation
	glutWireTorus(x, y, (int)z, (int)w);
}

void openGL::mglutWireDodecahedron(){
	//call the true glut implementation
	glutWireDodecahedron();
}





// solid model calls

void openGL::mglutSolidCone(double x, double y, double z, double w){
	//call the true glut implementation
	glutSolidCone(x, y, (int)z, (int)w);
}

void openGL::mglutSolidCube(double side){
	//call the true glut implementation
	glutSolidCube(side);
}


void openGL::mglutSolidSphere(double x, double y, double z){
	//call the true glut implementation
	glutSolidSphere(x, (int)y, (int)z);
}


void openGL::mglutSolidTeapot(double size){
	//call the true glut implementation
	glutSolidTeapot(size);
}

void openGL::mglutSolidTorus(double x, double y, double z, double w){
	//call the true glut implementation
	glutSolidTorus(x, y, (int)z, (int)w);
}

void openGL::mglutSolidDodecahedron(){
	//call the true glut implementation
	glutSolidDodecahedron();
}





void openGL::mgluLookAt(double ex, double ey, double ez, double lx, double ly, double lz, double ux, double uy, double uz){
	//call the true glu implementation
	gluLookAt(ex, ey, ez, lx, ly, lz, ux, uy, uz);
}


void openGL::mglColor3d(double r, double g, double b){
	//call the true gl implementation
	glColor3d(r, g, b);
}



void openGL::mglRotated(double angle, double r, double g, double b){
	//call the true gl implementation
	glRotated(angle, r, g, b);
}

void openGL::mglScaled(double x, double y, double z){
	//call the true gl implementation
	glScaled(x, y, z);
}
