#include #include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 #define RANGE WINDSIZEX*2.0/3.0 #define ERRORGENE 0.004044 void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); glColor3f(1.0, 0.0, 0.0); glDisable(GL_DITHER); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); } static void test(void) { GLfloat *buf; buf = (GLfloat *)malloc(WINDSIZEX*WINDSIZEY*3*sizeof(GLfloat)); GLfloat v1[2], v2[2]; GLfloat angle, X, Y, sum,limit,saveSum,range; GLfloat width; GLint k,j; // glGetFloatv(GL_LINE_WIDTH_RANGE, widthRange); // glGetFloatv(GL_LINE_WIDTH_GRANULARITY, &widthGranularity); width = 1.0 ; srand( (unsigned)time( NULL ) ); v1[0] = 0.0; v1[1] = 0.0; v2[0] = WINDSIZEX/4.0; v2[1] = 0.0; angle = rand()%360; // width = (width+widthGranularity < widthRange[1]) ? // width + widthGranularity : 1.0; glLineWidth(width); saveSum = v2[0]*width ; for (k = 0; k < 8; k++) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); X =rand()%RANGE+WINDSIZEY/3.0; Y = rand()%RANGE+WINDSIZEY/3.0; glTranslatef(X, Y, 0.0); glRotatef(angle, 0, 0, 1); glBegin(GL_LINES); glVertex2fv(v1); glVertex2fv(v2); glEnd(); glPopMatrix(); glFlush(); glReadPixels(0, 0, 100, 100, GL_RGB,GL_FLOAT, buf); for (j = 0; j < 100*100*3; j += 3) { sum += buf[j]; } limit = 2.0 * (0.25 + ERRORGENE)*(v2[0] + width); printf ("\n coverage is %f idea coverage is is %f error margin is %f \n", sum,saveSum,limit); if (abs(saveSum-sum) > limit) { printf ("\nthis case run failed, the translate cause Aliasing\n "); exit(-1) ; } } printf ("test ok "); } void display(void) { glViewport(0, 0, WINDSIZEX, WINDSIZEY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, WINDSIZEX, 0, WINDSIZEY); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); test(); } int main(int argc, char** argv) { // GLfloat *buf; // buf = (GLfloat *)malloc(WINDSIZEX*WINDSIZEY*3*sizeof(GLfloat)); glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(WINDSIZEX, WINDSIZEY); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); printf ("init ok"); glutDisplayFunc(display); glutMainLoop(); return 0 ; }