/************************************************************************* FILE: interface.cc Everything related to the display and the interface. Author: Dana Vrajitoru, IUSB Class: C481 B581 Computer Graphics **************************************************************************/ #include #include #include "interface.h" #include "trackball.h" #include "surface.h" extern float trans[]; int winWidth=600, winHeight=600; int list_id; // Callback for a display event. void display() { // Apply the trackball transformation. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(0, 0, 3.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glPopMatrix(); applyRotation(); glPushMatrix(); // The translation of the whole scene. glTranslatef(trans[0], trans[1], 0); glScalef(trans[2], trans[2], trans[2]); //glPolygonMode(GL_FRONT, GL_FILL); light_init(); glCallList(list_id); //material_blue(); //glutSolidTorus(1, 2, 10, 10); glutSwapBuffers(); } // Callback for an event resizing the window. void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90.0, w/h, 0.5, 40.0); /* if (w<=h) glFrustum(-10.0, 10.0, -10.0 * (GLfloat) h/ (GLfloat) w, 10.0* (GLfloat) h / (GLfloat) w, -10.0, 20.0); else glFrustum(-10.0, 10.0, -10.0 * (GLfloat) w/ (GLfloat) h, 10.0* (GLfloat) w / (GLfloat) h, -10.0, 20.0); */ glMatrixMode(GL_MODELVIEW); winWidth = w; winHeight = h; } // Callback for a keyboard event. void key(int key, int x, int y) { switch (key) { case GLUT_KEY_LEFT: trans[0] -= 0.1; break; case GLUT_KEY_RIGHT: trans[0] += 0.1; break; case GLUT_KEY_UP: trans[1] += 0.1; break; case GLUT_KEY_DOWN: trans[1] -= 0.1; break; case GLUT_KEY_PAGE_UP: trans[2] += 0.1; break; case GLUT_KEY_PAGE_DOWN: trans[2] -= 0.1; } display(); } // Defining one particlar set of material properties that make the // objects following a call to this function blue and kind of shiny. void material_blue() { GLfloat mat_specular[]={1.0, 1.0, 1.0, 1.0}; GLfloat mat_diffuse[]={0.0, 0.0, 0.5, 1.0}; GLfloat mat_ambient[]={0.5, 0.5, 1.0, 1.0}; GLfloat mat_shininess={2.5}; // define material proerties for front face of all polygons glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialf(GL_FRONT, GL_SHININESS, mat_shininess); } // Initialize one light source. void light_init() { GLfloat light_ambient[]={0.3, 0.3, 0.3, 1.0}; GLfloat light_diffuse[]={1.0, 0.5, 0.5, 1.0}; GLfloat light_specular[]={0.1, 0.1, 0.1, 1.0}; GLfloat light_position[] = {0.0, 5.0, -2.0, 1.0}; // set up ambient, diffuse, and specular components for light 0 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glShadeModel(GL_SMOOTH); /*enable smooth shading */ glEnable(GL_LIGHTING); /* enable lighting */ glEnable(GL_LIGHT0); /* enable light 0 */ glEnable(GL_DEPTH_TEST); /* enable z buffer */ //glEnable(GL_COLOR_MATERIAL); //glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE); glClearColor (0.1, 0.1, 0.1, 1.0); glColor3f (1, 0.0, 0.0); } // Create the display list for the scene. void create_display_list() { vector3f circle_points, circle_normals; circle_xy(2, 1, 0, 1.5, circle_points, circle_normals); list_id = glGenLists(1); // Create the display list. glNewList(list_id, GL_COMPILE); glColor3f(1.0, 0.0, 0.0); draw_line_strip(circle_points); material_blue(); glutSolidTorus(1, 2, 20, 20); glEndList(); }