#include #include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 #define TEXSIZE 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); // Check if GL_EXT_framebuffer_object is supported if (!strstr (glGetString (GL_EXTENSIONS), "GL_ARB_pixel_buffer_object")) { printf ("GL_ARB_pixel_buffer_object is not supported\n"); exit(0); } else { printf ("GL_ARB_pixel_buffer_object is supported\n"); } } static void test (void) { GLfloat red[] = { 1.0, 0.0, 0.0, 1.0 }; GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat green[] = { 0.0, 1.0, 0.0, 1.0 }; GLuint pbs[1]; GLuint textures[1]; int i, j; glClearColor (0.0, 0.0, 0.0, 1.0); glClear (GL_COLOR_BUFFER_BIT); GLubyte buffer[WINDSIZEX * WINDSIZEY * 4]; for (i = 0; i < WINDSIZEX * WINDSIZEY * 4; i++) buffer[i] = i % 16; glDrawPixels(WINDSIZEX, WINDSIZEY, GL_RGBA, GL_UNSIGNED_BYTE, buffer); glPixelStorei(GL_PACK_ALIGNMENT, 4); glGenBuffers(1, pbs); glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, pbs[0]); glBufferData(GL_PIXEL_PACK_BUFFER_EXT, TEXSIZE*TEXSIZE*4, NULL, GL_STREAM_DRAW); glReadPixels(0, 0, TEXSIZE, TEXSIZE, GL_BGRA, GL_UNSIGNED_BYTE, NULL); GLubyte *b = (GLubyte *) glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); for (j = 0; j < TEXSIZE; j++) { for (i = 0; i < TEXSIZE; i++) { printf ("(%d, %d) = [%d, %d, %d, %d]\n", i, j, b[(j * TEXSIZE + i) * 4], b[(j * TEXSIZE + i) * 4 + 1], b[(j * TEXSIZE + i) * 4 + 2], b[(j * TEXSIZE + i) * 4 + 3]); } } } 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 (0, 0); glutCreateWindow (argv[0]); init (); glutDisplayFunc (display); glutMainLoop (); return 0; }