/* antialiasing.c */ /* Purpose: This program demonstrates line antialiasing. */ #ifdef __APPLE__ #include #else #include #endif #include #include #define KEY_ESC 27 /* glut doesn't define this */ /* Global variables */ GLfloat angle = 0.0; /* how far is the line rotated? */ /* Functions */ void printHelp( void ) { fprintf(stdout, "Line antialiasing.\n\n" "r - rotate line\n" "a - toggle antialiasing\n" "Escape key - exit the program\n\n"); } GLvoid keyboard( GLubyte key, GLint x, GLint y) { switch (key) { case KEY_ESC: /* exit when escape key is pressed */ exit(0); break; case 'a': case 'A': { static GLboolean blendOn = GL_TRUE; blendOn ? glEnable( GL_BLEND ) : glDisable( GL_BLEND ); blendOn = !blendOn; } break; case 'r': angle += 2.0; break; } glutPostRedisplay(); } GLvoid specialkeys( GLint key, GLint x, GLint y) { switch (key) { case GLUT_KEY_F1: /* print Help information */ printHelp (); break; } } GLvoid checkError( const char* const label ) { GLenum error; error = glGetError(); while ( GL_NO_ERROR != error ) { fprintf( stderr,"%s: %s\n", label, gluErrorString(error) ); error = glGetError(); } } GLvoid display( GLvoid ) { /* Do all your OpenGL rendering here */ glClear( GL_COLOR_BUFFER_BIT ); glLoadIdentity(); glRotatef( angle, 0.0, 0.0, 1.0 ); /* Draw a single line */ glBegin(GL_LINES); glColor3f(1.0,0.25,0.25); glVertex2f( 0.0, 0.0 ); glColor3f(0.5,0.5,0.0); glVertex2f( 1.0, 0.0 ); glEnd(); checkError( "display" ); glFlush(); } void init( void ) { glClearColor( 1.0, 1.0, 1.0, 1.0); glLineWidth(3.0); glEnable( GL_LINE_SMOOTH ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); } int main( int argc, char *argv[] ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB ); glutCreateWindow( argv[0] ); printHelp( ); glutKeyboardFunc( keyboard ); glutSpecialFunc( specialkeys ); glutDisplayFunc( display ); init(); glutMainLoop(); return 0; }