#include <ostream.h>
#include "glut.h"
void main(int argc, char** argv)
{
//Initalize GLUT
glutInit(&argc,argv);
initGlut("3D Representations");
//3D initalization
//Initalize display-window
initDisplayWnd3D();
//Initalize projection and view plan
initView();
//Send graphics to display window
glutDisplayFunc(DisplayFcn3D);
//reshape function
glutReshapeFunc(winReshapeFcn);
//Display everything and wait in loop
glutMainLoop();
}
GLint initGlut(char* title)
{
//window ID
GLint WndID;
//Initialize GLUT
//Set display mode
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
//Set top-left dislplay-window position
glutInitWindowPosition(250,300);
//Set display window width and height
glutInitWindowSize(400,400);
//Creat display window
WndID=glutCreateWindow(title);
//return WndID
return WndID;
}
void initView(void)
{
//Viewing coordinate origin
GLfloat x0=100.0,y0=100.0,z0=100.0;
//Look-at point
GLfloat xRef=50.0,yRef=50.0,zRef=50.0;
//View-up vector
GLfloat Vx=0.0,Vy=0.0,Vz=1.0;
//Clear display window
glClear(GL_COLOR_BUFFER_BIT);
//Set the viewing parameters
gluLookAt(x0,y0,z0,xRef,yRef,zRef,Vx,Vy,Vz);
glMatrixMode(GL_PROJECTION);
}
void initDisplayWnd3D(void)
{
//Set display-window color to black
glClearColor(0.0,0.0,0.0,0.0);
//Clear display window
glClear(GL_COLOR_BUFFER_BIT);
//Set projection parameters
glMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_PROJECTION);
glOrtho(-200.0,200.0,-200.0,200.0,-200.0,200.0);
}
void winReshapeFcn(GLint newWidth,GLint newHeight)
{
glViewport(0,0,newWidth,newHeight);
glMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_PROJECTION);
glOrtho(-200.0,200.0,-200.0,200.0,- 200.0,200.0);
glClear(GL_COLOR_BUFFER_BIT);
}
void DisplayFcn3D(void)
{
//Set parameters for a square fill area
//Set fill color to green
glColor3f(0.0,1.0,0.0);
glPolygonMode(GL_FRONT,GL_LINE);
//Wire-frame back face
glPolygonMode(GL_BACK,GL_FILL);
glBegin(GL_QUADS);
glVertex3f(0.0,0.0,0.0);
glVertex3f(150.0,0.0,0.0);
glVertex3f(150.0,150.0,0.0);
glVertex3f(0.0,150.0,0.0);
glEnd();
//Postion and display wire-frame cone
glColor3f(1.0,0.0,0.0);
glPushMatrix();
glTranslatef(100.0,-50.0,0);
glutWireCone(50.0,150.0,7,6);
glPopMatrix();
//Position and display wire-frame sphere
glColor3f(0.0,1.0,0.0);
glPushMatrix();
glTranslatef(50.0,50.0,0);
glutWireSphere(60.0,8,6);
glPopMatrix();
glFlush();
}