From a54a466252f41004b5199995f9bfda8072f7f09a Mon Sep 17 00:00:00 2001
From: "chirs241097@gmail.com"
 <chirs241097@gmail.com@c17bf020-1265-9734-9302-a83f62007ddb>
Date: Sun, 30 Mar 2014 06:57:20 +0000
Subject: Add screen shot, fix screen shot bug in hge_unix.

---
 CHANGELOG.TXT  |  2 ++
 hge/hge_impl.h |  1 +
 hge/system.cpp | 22 ++++++++++++++++++++--
 main.cpp       |  1 +
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT
index 44ee83d..caf8588 100755
--- a/CHANGELOG.TXT
+++ b/CHANGELOG.TXT
@@ -12,6 +12,8 @@ Pre-Released versions:
 Bump version!
 New assessment level "density test"...
 New assessment level "pinball"...
+Add screen shot. Press S for a screen shot.
+Fix the upside down screen shot output.
 
 0.9.0-0_PR (b78)
 First two assessment levels.
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 ...
diff --git a/main.cpp b/main.cpp
index 7224a6c..5c351f3 100644
--- a/main.cpp
+++ b/main.cpp
@@ -810,6 +810,7 @@ bool FrameFunc()
 			fnt->printf(5, 150, HGETEXT_LEFT, "Multiplier: %.2lf",mult);
 		}
 	}
+	if(hge->Input_GetKeyStateEx(HGEK_S)==HGEKST_HIT)hge->System_Snapshot();
 	hge->Gfx_EndScene();
 	return false;
 }
-- 
cgit v1.2.3