+void Screen::ScreenShot(const char * filename) const
+{
+ Debug("Attempting to save BMP to file %s", filename);
+
+ int w = ViewportWidth();
+ int h = ViewportHeight();
+ unsigned char * pixels = new unsigned char[w*h*4];
+ if (pixels == NULL)
+ Fatal("Failed to allocate %d x %d x 4 = %d pixel array", w, h, w*h*4);
+
+ glReadPixels(0,0,w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+
+ SDL_Surface * surf = SDL_CreateRGBSurfaceFrom(pixels, w, h, 8*4, w*4, 0,0,0,0);
+ if (surf == NULL)
+ Fatal("Failed to create SDL_Surface from pixel data - %s", SDL_GetError());
+
+ if (SDL_SaveBMP(surf, filename) != 0)
+ Fatal("SDL_SaveBMP failed - %s", SDL_GetError());
+
+ SDL_FreeSurface(surf);
+ delete [] pixels;
+ Debug("Succeeded!");
+}