//*****************************************************************************************
// 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.
*/
//******************************************************************************************
	

// This code adds a basic display callback function to the code developed previously
// Addition of the display callback also includes setting the background to a uniform
// black color and clearing the background to that color. There is a small white square
// drawn in the screen.
// Try the following
// 1. Change the window size, what happens to the square ? Why ? 
// 2. Alter the color of the background color.
// 3. Try altering the polygon, add more points and change the color
// 4. Copy the polygon code and add a second polygon on the screen

#include "stdafx.h"
#include <glut.h>


void display( )
{

	// 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. );
}

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( );

	// Assign a display 'callback function'
	glutDisplayFunc( display );

	// Enter the graphics loop
	glutMainLoop( );

	return 0;
}


