
//intro to openGL

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;


//Class:    CS 402, 
//Purpose: intro to OpenGL
#include<glut.h>


//**********************************************************************
//A function to display scene
void Display(void)
{
	//clear the window with the current clearing color
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0f,1.0f,0.0f);//set foreground color to yellow

	glBegin(GL_LINES);
		glVertex2f(25.0f,150.0f);
		glVertex2f(45.0f,250.0f);
		glVertex2f(30.0f,15.0f);
		glVertex2f(35.0f,125.0f);
	glEnd();

	
	glBegin(GL_TRIANGLES);
	
		glVertex2f(43.5f,137.5f);
		glVertex2f(34.5f,36.5f);
		glVertex2f(65.5f,77.5f);
	
	glEnd();

	glBegin(GL_QUADS);
		glVertex2f(25.0f, 49.0f);
		glVertex2f(50.0f, 70.0f);
		glVertex2f(35.0f, 60.0f);
		glVertex2f(75.0f, 30.0);
	glEnd();
	//flush drawing comands
	glutSwapBuffers();
}


//**********************************************************************
//set up the rendering state for OpenGL
void Initialize()
{
	//set the background color to red
	//glClearColor(1.0f,.0f,0.0f,1.0f);
	//background to green
	//glClearColor(0.0, 1.0, 0, 0);
	//background to blue
	glClearColor(0,0,1,0);
}

void ChangeSize(GLsizei w, GLsizei h)
{
	//prevent division by zero
	if(h==0)
		h=1;
	//set viewport to woindow dimensions
	glViewport(0,0,w,h);

	//reset the coordinate system
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	//Establish clipping volume ((left, right, bottom, top, near, far)
	glOrtho(0.0f,200.0f,0.0f,360.0f,1.0f,-1.0f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void main(void)
{
	//Initializes the display mode of the GLUT library OpenGL window 
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

	//create a window with this title
	glutCreateWindow("Introduction");

	//set the function for GLUT to call when the window needs to be 
	//partially or completely redrawn
	glutDisplayFunc(Display);

	//Set the function for GLUT to call when the window gets resized
	glutReshapeFunc(ChangeSize);

	Initialize();

	//start the Glut main loop
	glutMainLoop();
}
