/* 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 { WIRETORUS, SOLIDTORUS } 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, 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) { GLfloat dx, dy; glMatrixMode(GL_PROJECTION); glLoadIdentity(); dx = (eyedx/focus)*(focus-near); dy = (eyedy/focus)*(focus-near); glFrustum(left+dx,right+dx,bottom+dy,top+dy,near,far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(eyedx,eyedy,0.0); } 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(); //clear to light green, draw text glClearColor(0.7,1,0.7,0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(0,0,0); twSetFont("helvetica", 18); twDrawString(GAP,25,"Original image"); twDrawString(GAP*2+wWidth, 25, "Image after antialiasing"); glutSwapBuffers(); } //draws planetary figure in wireframe void drawWireFrame() { glPushMatrix(); glTranslatef(0,0,-6); twColorName(TW_MAGENTA); glutWireSphere(2.5,15,15); glRotatef(-75,1,1,0); twColorName(TW_BLUE); glutWireTorus(0.4,3.0,10,10); glPopMatrix(); } //draws solid planetary figure void drawPolygons() { glPushMatrix(); glTranslatef(0,0,-6); twColorName(TW_MAGENTA); glutSolidSphere(2.5,15,15); glRotatef(-75,1,1,0); twColorName(TW_BLUE); glutSolidTorus(0.4,3.0,10,10); 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(); glFlush(); glutSwapBuffers(); } //displays image after antialiasing void smoothDisplay() { int jitter; int numJitters = 8; glClear(GL_ACCUM_BUFFER_BIT); for(jitter=0; jitter