Page 410 OpenGL Super Bible! temp; /* Temporary (Web server address)

Page 410 OpenGL Super Bible! temp; /* Temporary var for swapping */ /* * Grab the current viewport */ glGetIntegerv(GL_VIEWPORT, viewport); /* * Allocate memory for the header and bitmap */ if ((*info = (BITMAPINFO *)malloc(sizeof(BITMAPINFOHEADER))) == NULL) { /* * Couldn’t allocate memory for bitmap info - return NULL */ return (NULL); }; width = viewport[2] * 3; /* Real width of scanline */ width = (width + 3) & ~3; /* Aligned to 4 bytes */ bitsize = width * viewport[3]; /* Size of bitmap, aligned */ if ((bits = calloc(bitsize, 1)) == NULL) { /* * Couldn’t allocate memory for bitmap pixels - return NULL */ free(*info); return (NULL); }; /* * Read pixels from the framebuffer */ glFinish(); /* Finish all OpenGL commands */ glPixelStorei(GL_PACK_ALIGNMENT, 4); /* Force 4-byte alignment */ glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_SKIP_ROWS, 0); glPixelStorei(GL_PACK_SKIP_PIXELS, 0); glReadPixels(0, 0, viewport[2], viewport[3], GL_RGB, GL_UNSIGNED_BYTE, bits); /* * Swap red and blue for the bitmap */ for (i = 0; i < viewport[3]; i ++) for (j = 0, rgb = ((GLubyte *)bits) + i * width; j < viewport[2]; j ++, rgb += 3)
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Leave a Reply