@@ -178,9 +178,10 @@ function HandleKeyDown(eventType, eventData)
local graphics = GetGraphics()
local screenshot = Image()
graphics:TakeScreenShot(screenshot)
- screenshot:FlipVertical()
local timeStamp = Time:GetTimeStamp()
- screenshot:SavePNG("Data/" .. timeStamp .. " Screenshot.png") -- Here we save in the Data folder with date and time appended
+ timeStamp = string.gsub(timeStamp, "[:. ]", "_")
+ -- Here we save in the Data folder with date and time appended
+ screenshot:SavePNG(GetFileSystem():GetProgramDir() .. "Data/Screenshot_" .. timeStamp .. ".png")
end
@@ -174,10 +174,11 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
// Take screenshot
else if (key == '9')
{
- Image@ screenshot = Image();
- graphics.TakeScreenShot(screenshot);
- screenshot.FlipVertical();
- screenshot.SavePNG("Data/" + time.timeStamp + " Screenshot.png"); // Here we save in the Data folder with date and time appended
- }
+ Image@ screenshot = Image();
+ graphics.TakeScreenShot(screenshot);
+ // Here we save in the Data folder with date and time appended
+ screenshot.SavePNG(fileSystem.programDir + "Data/Screenshot_" +
+ time.timeStamp.Replaced(':', '_').Replaced('.', '_').Replaced(' ', '_') + ".png");
+ }
}
@@ -270,6 +270,7 @@ F2 Toggle debug HUD
6 Cycle shadow filtering quality
7 Toggle occlusion culling
8 Toggle dynamic instancing
+9 Take a screenshot and save to the Data directory
\endverbatim
@@ -539,6 +539,8 @@ bool Graphics::TakeScreenShot(Image& destImage)
destImage.SetSize(width_, height_, 3);
glReadPixels(0, 0, width_, height_, GL_RGB, GL_UNSIGNED_BYTE, destImage.GetData());
+ // On OpenGL we need to flip the image vertically after reading
+ destImage.FlipVertical();
return true;
@@ -24,6 +24,7 @@
#include "Console.h"
#include "DebugHud.h"
#include "Engine.h"
+#include "FileSystem.h"
#include "Graphics.h"
#include "InputEvents.h"
#include "Renderer.h"
@@ -225,8 +226,9 @@ void Sample::HandleKeyDown(StringHash eventType, VariantMap& eventData)
Graphics* graphics = GetSubsystem<Graphics>();
Image screenshot(context_);
graphics->TakeScreenShot(screenshot);
- screenshot.SavePNG("Data/" + Time::GetTimeStamp() + "Screenshot.png"); // Here we save in the Data folder with date and time appended
+ screenshot.SavePNG(GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Screenshot_" +
+ Time::GetTimeStamp().Replaced(':', '_').Replaced('.', '_').Replaced(' ', '_') + ".png");