#include #include #define GL_GLEXT_PROTOTYPES #include int main(int argc, char *argv[]) { int width = 300, height = 300; Display *dpy = XOpenDisplay(NULL); int ncfg, attrs[] = {GLX_DOUBLEBUFFER, GL_TRUE, None}; GLXFBConfig *dconfigs = glXChooseFBConfig(dpy, 0, attrs, &ncfg); int pbattrs[] = {GLX_PBUFFER_WIDTH, width, GLX_PBUFFER_HEIGHT, height, GLX_PRESERVED_CONTENTS, True, None}; GLXPbuffer pbuffer = glXCreatePbuffer(dpy, dconfigs[0], pbattrs); GLXContext ctx = glXCreateNewContext(dpy, dconfigs[0], GLX_RGBA_TYPE, NULL, True); glXMakeCurrent(dpy, pbuffer, ctx); GLuint pbo; glGenBuffers(1, &pbo); glBindBuffer(GL_PIXEL_UNPACK_BUFFER_EXT, pbo); int size = width*height*4; glBufferData(GL_PIXEL_UNPACK_BUFFER_EXT, size, NULL, GL_STREAM_DRAW); void *pixeldata = malloc(size); memset(pixeldata, 0x80, size); glBufferSubData(GL_PIXEL_UNPACK_BUFFER_EXT, 0, size, pixeldata); glDrawPixels(width, height, GL_BGRA, GL_UNSIGNED_BYTE, NULL); glXSwapBuffers(dpy, pbuffer); GLXPbuffer pbuffer2 = glXCreatePbuffer(dpy, dconfigs[0], pbattrs); glXMakeCurrent(dpy, pbuffer2, ctx); glBufferSubData(GL_PIXEL_UNPACK_BUFFER_EXT, 0, size, pixeldata); glDrawPixels(width, height, GL_BGRA, GL_UNSIGNED_BYTE, NULL); glXSwapBuffers(dpy, pbuffer2); free(pixeldata); glDeleteBuffers(1, &pbo); glXDestroyPbuffer(dpy, pbuffer); glXDestroyPbuffer(dpy, pbuffer2); return 0; }