X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=judge%2Fmanager%2Fgraphics.cpp;h=5710898428ba76e5e8449d1fd23e9d2d629b4bc4;hp=5b708df75ab0b5edf833db1b455e6388737e8d33;hb=5f9adddd695f2664a0d690b59a779e40b51ade3d;hpb=1a03b2543b67f0551e62babec4cd119f1e0e4640 diff --git a/judge/manager/graphics.cpp b/judge/manager/graphics.cpp index 5b708df..5710898 100644 --- a/judge/manager/graphics.cpp +++ b/judge/manager/graphics.cpp @@ -3,6 +3,7 @@ #include #include +#ifdef BUILD_GRAPHICS #undef DEBUG //#define DEBUG @@ -127,6 +128,7 @@ void Texture::Draw(int x, int y, double angle , double scale ) } + Font::Font(const char * filename, int newWidth, int newHeight) : Texture(filename), width(newWidth), height(newHeight) { @@ -442,8 +444,85 @@ Colour Graphics::ConvertColour(Uint8 from) return result; } +void Graphics::Wait(int n) +{ + SDL_Delay(n); +} + +/* Writes an upside down image??? +void Graphics::ScreenShot(const char * fileName) +{ + + std::vector< GLubyte > pixeldata; + pixeldata.resize( swidth * sheight * 3 ); + SDL_Surface* image = SDL_CreateRGBSurface(SDL_SWSURFACE, screenWidth, screenHeight, 24,255U << (16),255 << (8),255 << (0),0); + + SDL_LockSurface( image ); + + glReadPixels(0, 0, swidth, sheight, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)image->pixels); + + + + SDL_UnlockSurface( image ); + + SDL_SaveBMP(image, fileName); + SDL_FreeSurface( image ); +} +*/ + + +// Hacky code from http://www.gamedev.net/topic/389159-bitmap-file-saving-problem/ +// Should probably make it nicer + +void Graphics::ScreenShot(const char * fileName) +{ + + unsigned char *pixels = (unsigned char*)(malloc (screenWidth * screenHeight * 3)); + + SDL_Surface* reversed_image = SDL_CreateRGBSurface(SDL_SWSURFACE, screenWidth, screenHeight, 24, + 255U << (0), // Blue channel + 255 << (8), // Green channel + 255 << (16), // Red channel + 0 /* no alpha! */); + + SDL_LockSurface( reversed_image ); + + // Read in the pixel data + glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB, GL_UNSIGNED_BYTE, pixels); + + SDL_UnlockSurface( reversed_image ); + + /* At this point the image has been reversed, so we need to re-reverse it so that + it is the correct way around. We do this by copying the "image" pixels to another + surface in reverse order */ + SDL_Surface* image = SDL_CreateRGBSurface(SDL_SWSURFACE, screenWidth, screenHeight, 24, + 255U << (0), // Blue channel + 255 << (8), // Green channel + 255 << (16), // Red channel + 0 /* no alpha! */); + + uint8_t *imagepixels = reinterpret_cast(image->pixels); + // Copy the "reversed_image" memory to the "image" memory + for (int y = (screenHeight - 1); y >= 0; --y) { + uint8_t *row_begin = pixels + y * screenWidth * 3; + uint8_t *row_end = row_begin + screenWidth * 3; + + std::copy(row_begin, row_end, imagepixels); + + // Advance a row in the output surface. + imagepixels += image->pitch; + } + + // Save file + SDL_SaveBMP(image, fileName); + + // Clear memory + SDL_FreeSurface( reversed_image ); + SDL_FreeSurface( image ); +} +#endif //BUILD_GRAPHICS