#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 void init(void) { glClearColor(0.0, 0.0, 0.0, 1.0); glColor4f(0.0, 1.0, 0.0, 1.0); glDisable(GL_DITHER); } static void test(void) { GLfloat *buf; int i, j; int colored = 0; glClear(GL_COLOR_BUFFER_BIT); glScissor(4, 3, 25, 1); glEnable(GL_SCISSOR_TEST); //glPointSize(2.0); glEnable(GL_POINT_SMOOTH); glBegin(GL_POINTS); for (i = 0; i < WINDSIZEX; i++) { for (j = 0; j < WINDSIZEY; j++) { glVertex2f (i + 0.5, j + 0.5); } } glEnd(); buf = (GLfloat *)malloc(WINDSIZEX*WINDSIZEY*sizeof(GLfloat)); glReadPixels(0, 0, WINDSIZEX, WINDSIZEY, GL_GREEN, GL_FLOAT, buf); for ( i = 0; i < WINDSIZEX * WINDSIZEY; i++) if (buf[i] == 1.0) colored++; printf("colored point number is %d, should be 25\n", colored); } 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) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(WINDSIZEX, WINDSIZEY); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }