/* Displays a picture with and without aliasing using jittering to achieve smooth edges on the picture without aliasing. Written by Caroline Geiersbach and Scott D. Anderson scott.anderson@acm.org Summer 2003 */ #include #include #include //menu typedef enum { BEAR, TEAPOT, TETRAHEDRON } options; int rMenu; int menuNum = 0; void myMenu(); //window values #define GAP 35 GLuint wWidth = 400; GLuint wHeight = 400; GLuint mainWidth = wWidth*2+GAP*3; GLuint mainHeight = wHeight+GAP*2; GLuint window, rightWin, leftWin; void redisplayAll(); //values for the camera GLfloat near = 3.0; GLfloat far = 21.0; GLfloat left = -3.0; GLfloat right = 3.0; GLfloat bottom = -3.0; GLfloat top = 3.0; void reshape(int width, int height) { glViewport(0,0,width, height); } /* Set up camera. Note that near and far remain fixed; for scene antialiasing we no longer move the eye location. */ void accCamera(GLfloat pixdx, GLfloat pixdy) { GLfloat dx, dy; GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); glMatrixMode(GL_PROJECTION); glLoadIdentity(); dx = -(pixdx*wWidth)/(GLfloat)viewport[2]; dy = -(pixdy*wHeight)/(GLfloat)viewport[3]; glFrustum(left+dx,right+dx,bottom+dy,top+dy,near,far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void myCamera() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(left,right,bottom,top,near,far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void lighting() { GLfloat direction[]={1,1,1,0}; GLfloat ambientDiffuse[]={0.8,0.8,0.8,1}; GLfloat specular[]={1,1,1,1}; glShadeModel(GL_SMOOTH); glLightfv(GL_LIGHT0,GL_POSITION,direction); glLightfv(GL_LIGHT0,GL_AMBIENT_AND_DIFFUSE,ambientDiffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,specular); glEnable(GL_LIGHT0); twAmbient(0.5); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE); glEnable(GL_LIGHTING); } //parent window void mainDisplay() { //set up camera glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0,mainWidth,mainHeight,0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); twDisplayInit(); glDisable(GL_LIGHTING); glColor3f(0,0,0); twSetFont("helvetica", 18); twDrawString(GAP,25,"Original image"); twDrawString(GAP*2+wWidth, 25, "Image after antialiasing"); glEnable(GL_LIGHTING); glutSwapBuffers(); } twTriple teapotRed = {1,0,0}; twTriple tetraBlue = {0,0,1}; void drawObject() { switch(menuNum) { case(BEAR): glPushMatrix(); glTranslatef(0,0,-4); glScalef(6,6,6); twTeddyBear(); glPopMatrix(); break; case(TEAPOT): glPushMatrix(); twColor(teapotRed, 0.7, 128); glTranslatef(0,0,-5.5); glRotatef(25,1,0,0); glScalef(2.5,2.5,2.5); glutSolidTeapot(1); glPopMatrix(); break; case(TETRAHEDRON): glPushMatrix(); twColor(tetraBlue, 0.7, 128); glTranslatef(0,0,-6.5); // glRotatef(90,1,0,0); glScalef(3.5,3.5,3.5); glutSolidIcosahedron(); glPopMatrix(); break; } glPopMatrix(); } //displays image before antialiasing void jaggedDisplay() { myCamera(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLineWidth(3); // if(menuNum==0) drawWireFrame(); //else drawPolygons(); drawObject(); glFlush(); glutSwapBuffers(); } //displays image after antialiasing void smoothDisplay() { int jitter; int numJitters = 8; glClear(GL_ACCUM_BUFFER_BIT); for(jitter=0; jitter