/* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
w=400;
h=500;
unsigned char * pixels = new unsigned char[w*h*4]; // 4 bytes for RGBA
glReadPixels(0,0,w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
SDL_Surface * surf = SDL_CreateRGBSurfaceFrom(pixels, width, height, 8*4, width*4, rmask, gmask, bmask, amask);
SDL_SaveBMP(surf, filename);
SDL_FreeSurface(surf);
delete [] pixels;
沒有留言:
張貼留言