/*
Dr. Yoon 
Basic OpenGL using GLUT ( Sample structure for a program)
Structure was tested only on Windows, but it should be compatable
with other operating systems 
*/

#include <gl/glut.h>

//This will remove the console window.  remove this if you would like
//the console window for debugging purposes
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")


//These commands tell the compiler to link to these libraries at
//compile time.  

#pragma comment(lib, "glut32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "opengl32.lib")

//Any initalizations that should only be done once should be put here
bool init(void)
{
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	return true;
}

//Our rendering is done here, this is run each time the window needs to be 
//refreshed
void renderScene(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glBegin(GL_TRIANGLES);
		glVertex3f(0.0f, 0.0f, 0.0f);
		glVertex3f(10.0f, 5.0f, 0.0f);
		glVertex3f(0.0f, 10.0f, 0.0f);
	glEnd();

	glutSwapBuffers();
}


//Our reshape hander
void reshape(int w, int h)
{
	GLfloat nRange = 80.0f;

	//prevents divide by zero
	if(h==0)
		h=1;
	//Sets view port
	glViewport(0,0,w,h);

	//Set matrix stack
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	if(w <= h)
		glOrtho(-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
	else
		glOrtho(-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);

	//Return Matrix Stack
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

}


int main(int argc, char ** argv)
{
	glutInit(&argc, argv);							//GLUT initialization
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);	//Set glut display mode
	glutInitWindowSize(640, 480);					//Window Size
	glutCreateWindow("My First Program");			//Creates window
	init();											//our initations
	glutDisplayFunc(renderScene);
	glutReshapeFunc(reshape);

	glutMainLoop();							//This function never returns
	return 0;




}



