/* Demonstration of jittering to achieve the depth-of-field effect Written by Caroline Geiersbach and Scott D. Anderson scott.anderson@acm.org Summer 2003 */ #include #include #include #include /* values for the camera. compute near and far based on a bounding box of (-5,5,-5,5,-5,5).*/ GLfloat fovy=90; GLfloat ar=1; GLfloat near=3.0; GLfloat far=21.0; GLfloat left=-3; GLfloat right=3; GLfloat bottom=-3; GLfloat top=3; void reshape(int width, int height) { glViewport(0,0,width,height); } /* Set up camera. Note that near, far, and focus remain fixed; all that is modified with the accumulation buffer is the eye location.*/ void accCamera(GLfloat eyedx, GLfloat eyedy, GLfloat focus) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90,1,near,far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0+eyedx,0+eyedy,0,0,0,focus,0,1,0); } /*Draw teapot at the location (x,y,z) with the color (red, green, blue) */ void drawObject(GLfloat x, GLfloat y, GLfloat z, GLfloat scale, GLfloat red, GLfloat green, GLfloat blue) { glPushMatrix(); glTranslatef(x,y,z); glScalef(scale,scale,scale); twTriple color = {red, green, blue}; twColor(color,0.9,128.0); glBegin(GL_POLYGON); glVertex3f(-1,-1,0); glVertex3f(-1,1,0); glVertex3f(1,1,0); glVertex3f(1,-1,0); glEnd(); glPopMatrix(); } void display(void) { int jitter; int numJitters = 8; glClear(GL_ACCUM_BUFFER_BIT); for(jitter=0; jitter