/// Computer Graphics - Amir Hesami #pragma comment(lib, "opengl32.lib") // Link OpenGL32.lib #pragma comment(lib, "glu32.lib") // Link Glu32.lib #pragma comment(lib, "glut32.lib") // Link Glut32.lib#include #include #include #include #include #include const int screenWidth=640; const int screenHeight=480; void display(); void init(); void mykey(unsigned char ,int ,int ); void setPerVolume(double,double,double,double); void setViewport(int,int,int,int); void menu(int ); float red=0.0f,green=0.0f,blue=1.0f; int main(int argc,char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(screenWidth,screenHeight); glutInitWindowPosition(50,50); glutCreateWindow("Teapot /Computer Graphics - Amir Hesami "); glutCreateMenu(menu); glutAddMenuEntry("Red",1); glutAddMenuEntry("Green",2); glutAddMenuEntry("Blue",3); glutAddMenuEntry("Exit",4); glutAttachMenu(GLUT_RIGHT_BUTTON); init(); glutSetCursor(GLUT_CURSOR_CROSSHAIR); glutDisplayFunc(display); glutKeyboardFunc(mykey); glutMainLoop(); return 0; } void init() { setPerVolume(30,1.5,0.3,50); setViewport(0,screenWidth,0,screenHeight); } void setPerVolume(double viewAngle,double aspectRatio,double N,double F) { GLdouble eyeX=3; GLdouble eyeY=3; GLdouble eyeZ=3; GLdouble lookX=0; GLdouble lookY=0.25; GLdouble lookZ=0; GLdouble upX=0; GLdouble upY=1; GLdouble upZ=0; glClear (GL_COLOR_BUFFER_BIT); glClearColor(1.0,1.0,1.0,1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(viewAngle,aspectRatio,N,F); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyeX,eyeY,eyeZ,lookX,lookY,lookZ,upX,upY,upZ); } void setViewport(int left,int right,int bottom,int top) { glViewport(left,bottom,right-left,top-bottom); } void display() { glColor3f(red,green,blue); init(); glutWireTeapot(1); glFlush(); } void mykey(unsigned char key,int x,int y) { if(key=='Q' ||key=='q') exit(0); } void menu(int value) { if(value==1) { red=1.0f; green=0.0f; blue=0.0f; display(); } if(value==2) { red=0.0f; green=1.0f; blue=0.0f; display(); } if(value==3) { red=0.0f; green=0.0f; blue=1.0f; display(); } if(value==4) { exit(0); } }