#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 void init(void) { } static void test(void) { GLfloat *pixels; int i; GLubyte bitmap[8*8]; pixels = (GLfloat *) malloc(WINDSIZEX*WINDSIZEY*sizeof(GLfloat)); for(i = 0; i < 8*8; i++){ bitmap[i]=0xFF; } /* glDrawBuffer(GL_FRONT_LEFT); glClear(GL_COLOR_BUFFER_BIT); glDrawBuffer(GL_BACK_LEFT); glClear(GL_COLOR_BUFFER_BIT); */ glDrawBuffer(GL_LEFT); glClearColor(1.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT); glColor4f(0.0, 1.0, 0.0, 0.0); glRasterPos2f(3 + 0.25, 6 + 0.25); glBitmap (8, 8, 0.0, 0.0, 0.0, 0.0, bitmap); glReadBuffer(GL_FRONT_LEFT); glReadPixels(0, 0, WINDSIZEX, WINDSIZEY, GL_GREEN, GL_FLOAT, pixels); int colored = 0; for(i = 0; i < WINDSIZEX *WINDSIZEY; i++) if(pixels[i] == 1.0) colored++; printf("colored pixel : %d\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_DOUBLE | GLUT_RGB); glutInitWindowSize(WINDSIZEX, WINDSIZEY); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }