From a54a466252f41004b5199995f9bfda8072f7f09a Mon Sep 17 00:00:00 2001 From: "chirs241097@gmail.com" Date: Sun, 30 Mar 2014 06:57:20 +0000 Subject: Add screen shot, fix screen shot bug in hge_unix. --- hge/hge_impl.h | 1 + hge/system.cpp | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'hge') diff --git a/hge/hge_impl.h b/hge/hge_impl.h index e09a321..7361274 100644 --- a/hge/hge_impl.h +++ b/hge/hge_impl.h @@ -339,6 +339,7 @@ public: //int _format_id(D3DFORMAT fmt); void _SetBlendMode(int blend); void _SetProjectionMatrix(int width, int height); + int _flipSDLSurface(int pitch, int height, void* image_pixels); // Audio diff --git a/hge/system.cpp b/hge/system.cpp index 915ffe1..b7c112c 100644 --- a/hge/system.cpp +++ b/hge/system.cpp @@ -675,7 +675,8 @@ void CALL HGE_Impl::System_Snapshot(const char *filename) SDL_Surface *screen = SDL_GetVideoSurface(); SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h, 24, rmask, gmask, bmask, 0); pOpenGLDevice->glReadPixels(0, 0, screen->w, screen->h, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels); - STUBBED("image is probably upside down"); + //flip the image so that it won't be upside down... + _flipSDLSurface(surface->pitch,surface->h,surface->pixels); SDL_SaveBMP(surface, filename); SDL_FreeSurface(surface); } @@ -897,5 +898,22 @@ bool HGE_Impl::_ProcessSDLEvent(const SDL_Event &e) return true; } - +int HGE_Impl::_flipSDLSurface(int pitch, int height, void* image_pixels) +{ + int index; + void* temp_row; + int height_div_2; + + temp_row=(void *)malloc(pitch); + assert(temp_row); + height_div_2 = (int) (height * .5); + for(index = 0; index < height_div_2; index++) + { + memcpy((Uint8 *)temp_row,(Uint8 *)(image_pixels)+pitch*index,pitch); + memcpy((Uint8 *)(image_pixels)+pitch*index,(Uint8 *)(image_pixels)+pitch*(height-index-1),pitch); + memcpy((Uint8 *)(image_pixels)+pitch*(height-index-1),temp_row,pitch); + } + free(temp_row); + return 0; +} // end of system_unix.cpp ... -- cgit v1.2.3