Kaynağa Gözat

Sanitate screenshot name in the samples to ensure saving it succeeds. Prepend the executable path properly. Flip image in OpenGL Graphics::TakeScreenShot() instead of having the user to do it.

Lasse Öörni 12 yıl önce
ebeveyn
işleme
5062dbba42

+ 3 - 2
Bin/Data/LuaScripts/Utilities/Sample.lua

@@ -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
     end
 end

+ 6 - 5
Bin/Data/Scripts/Utilities/Sample.as

@@ -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");
+        }
     }
 }

+ 1 - 0
Docs/GettingStarted.dox

@@ -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
 
 

+ 2 - 0
Source/Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -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;
 }

+ 5 - 3
Source/Samples/Sample.inl

@@ -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.FlipVertical();
-            screenshot.SavePNG("Data/" + Time::GetTimeStamp() + "Screenshot.png"); // Here we save in the Data folder with date and time appended
-	    }
+            // 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");
+        }
     }
 }