//*****************************************************************************************
// Disclaimer, Authorship and License
/*
	This code has been written to serve as a learning tool for the course MAE 410-574, 
	Virtual Reality Applications and Research, Spring 2007.
	
	Large parts of the code has been adapted from the examples given in the OpenGL 
	Programming Guide by Woo et. al and also from Computer Graphics Using OpenGL by FS Hill
	Some parts of the code has also been adapted from various resources available through 
	out the internet.I thank all those whose code and resources I have used to write these 
	examples. You may use this code for any non-commerical purpose. Feel free to include 
	and use parts of this code for your own application, but remember that this code is not
	entirely bug free, use it at your own risk..If you plan on using the code for your any 
	academic purpose please drop me an email. I would like to attach a link to your course 
	from my home page.

	The Author of this code is Govindarajan Srimathveeravalli, Dept. of Mech and Aero Eng. ,
	University at Buffalo.
*/
//******************************************************************************************
// We add a "reshape" call to handle proper resizing of the windows
// and also we add an orthographic "camera" in order to "view" the 
// window properly.
// Try the following
// 1. Alter the values provided in glOrtho() command and see what
//    it affects in the output

#include "glut.h"

void reshape( int w, int h)
{
	// nothing to see here, please move along
	glutPostRedisplay();
}

void display( )
{
	// nothing to see here, please move along

	// Clear the background before drawing
	glClear( GL_COLOR_BUFFER_BIT );

	// Coloring
	glColor3f( 1., 1., 1. );

	// Actual code to do the drawing
	glBegin( GL_POLYGON );
		glVertex3f( 0.25, 0.25, 0. );
		glVertex3f( 0.75, 0.25, 0. );
		glVertex3f( 0.75, 0.75, 0. );
		glVertex3f( 0.25, 0.75, 0. );
	glEnd();
	
	// Ensure all drawing commands are executed
	glFlush( );
}

void init ( )
{
	// Set the background 
	glClearColor( 0., 0., 0. , 0. );

	// Setting up a rudimentary camera
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity( );
	glOrtho( -1., 1., -1., 1., -1., 1. );	
}

int main(int argc, char* argv[])
{

	// Initialize a window with command line arguments
	glutInit( &argc, argv );
	// Provide window with buffering, coloring information
	glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
	//glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
	// Position and Size the window
	glutInitWindowPosition( 50, 50 );
	glutInitWindowSize( 200, 200 );
	// Create the window with the given features with a 'suitable title'
	glutCreateWindow( "Hello World" );

	// do some initialization like setting up background color, camera, projection type etc.
	init( );

	// The reshape function is called everytime the window is relocated or resized ! duh
	glutReshapeFunc( reshape );
	
	// Assign a display 'callback function'
	glutDisplayFunc( display );

	// Enter the graphics loop
	glutMainLoop( );

	return 0;
}


