#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 static GLubyte bitmap[8 * 8 / 8]; void init (void) { int i; GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 }; glClearColor (0.0, 0.0, 0.0, 1.0); glColor4fv (white); glDisable (GL_DITHER); } static void test (void) { int i, j; GLfloat red[] = { 0.0, 1.0, 0.0, 1.0 }; GLfloat buf[3]; for(i = 0; i < (sizeof (bitmap) / sizeof (bitmap[0])); i++){ bitmap[i]=0xFF; } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glClearColor (0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glDrawBuffer(GL_NONE); glColor4fv (red); glRasterPos2f(0.25, 0.25); glBitmap (8, 8, 0.0, 0.0, 0.0, 0.0, bitmap); glReadPixels(0, 0, 1, 1, GL_RGB, GL_FLOAT, buf); printf("read back (0, 0) = [%f, %f, %f]\n", buf[0], buf[1], buf[2]); printf("should be [%f, %f, %f]\n", 0.0, 0.0, 0.0); } void display (void) { glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0, WINDSIZEX, 0, WINDSIZEX); test (); } int main (int argc, char **argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize (WINDSIZEX, WINDSIZEY); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init (); glutDisplayFunc (display); glutMainLoop (); return 0; }