//display function void display() { glMatrixMode(GL_PROJECTION); //sets current matrix mode to projection matrix glLoadIdentity(); //replaces current matrix with identity matrix glMatrixMode(GL_MODELVIEW); //sets current matrix mode to model view matrix glScalef(1.2,1.2,1.2); //scaling table(0.85,0.15,0.15,0.45); glTranslatef(-0.2,0.07,0); //translation glColor3f(0.4,0,0.7); drawwall(); glColor3f(1,0,0.15); //draw chair drawchair(0.15,0.35); glColor3f(0.0,1,0.0); //set color to green drawWorm(); //draw worm glColor3f(0.8,0.1,0.5); //set color to blue drawteapot(0.25,0.55); //draw teapot glPushMatrix(); glColor3f(1,0.95,0.8); //set color glTranslated(0,0,0.15); drawbook1(0.25,0.25); //draw book1 glPopMatrix(); glPushMatrix(); //drawbook2 glColor3f(0.93,0.86,0.51); glTranslated(0,0,0.15); drawbook2(0.25,0.25); glPopMatrix(); glColor3f(0.7,0.7,0.7); //set color to white drawglass(); //draw glass glColor3f(0,0,0); drawlamp(); glColor3f(1,1,1); //set color to white glTranslatef(0.2,-0.07,0); glTranslatef(-0.0,0.45+0.09,-0.25); glRotated(90,0,1,0); glRotated(-90,0,1,0); glTranslatef(0.0,-0.45-0.09,0.25); glScalef(1/1.2,1/1.2,1/1.2); glEnd(); glFlush(); //forces execution of opengl functions in finite time }
static void draw(void) { static char frbuf[80] = ""; dojoy(); glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); if(usetex) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D); if(fog) glEnable(GL_FOG); else glDisable(GL_FOG); glEnable(GL_LIGHTING); glShadeModel(GL_SMOOTH); glPushMatrix(); calcposobs(); gluLookAt(obs[0],obs[1],obs[2], obs[0]+dir[0],obs[1]+dir[1],obs[2]+dir[2], 0.0,0.0,1.0); drawlight1(); glCallList(basedlist); drawteapot(); drawlight2(); glPopMatrix(); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glShadeModel(GL_FLAT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-0.5,639.5,-0.5,479.5,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3f(1.0,0.0,0.0); glRasterPos2i(10,10); printstring(GLUT_BITMAP_HELVETICA_18,frbuf); glRasterPos2i(350,470); printstring(GLUT_BITMAP_HELVETICA_10,"Teapot V1.2 Written by David Bucciarelli ([email protected])"); if(help) printhelp(); reshape(WIDTH,HEIGHT); glutSwapBuffers(); Frames++; { GLint t = glutGet(GLUT_ELAPSED_TIME); if (t - T0 >= 2000) { GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; sprintf(frbuf, "Frame rate: %f", fps); printf("%s\n", frbuf); fflush(stdout); T0 = t; Frames = 0; } } }
static void draw(void) { static int count=0; static char frbuf[80]; float fr; dojoy(); glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); if(usetex) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D); if(fog) glEnable(GL_FOG); else glDisable(GL_FOG); glEnable(GL_LIGHTING); glShadeModel(GL_SMOOTH); glPushMatrix(); calcposobs(); gluLookAt(obs[0],obs[1],obs[2], obs[0]+dir[0],obs[1]+dir[1],obs[2]+dir[2], 0.0,0.0,1.0); drawlight1(); glCallList(basedlist); drawteapot(); drawlight2(); glPopMatrix(); if((count % FRAME)==0) { fr=gettime(); sprintf(frbuf,"Frame rate: %f",FRAME/fr); } glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); glShadeModel(GL_FLAT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-0.5,639.5,-0.5,479.5,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3f(1.0,0.0,0.0); glRasterPos2i(10,10); printstring(GLUT_BITMAP_HELVETICA_18,frbuf); glRasterPos2i(350,470); printstring(GLUT_BITMAP_HELVETICA_10,"Teapot V1.2 Written by David Bucciarelli ([email protected])"); if(help) printhelp(); reshape(WIDTH,HEIGHT); glutSwapBuffers(); count++; }