Browse Source

Extended Sample with ability to set window title and icon and take screenshots

Mike3D 12 years ago
parent
commit
0026f57899
1 changed files with 23 additions and 1 deletions
  1. 23 1
      Bin/Data/LuaScripts/Utilities/Sample.lua

+ 23 - 1
Bin/Data/LuaScripts/Utilities/Sample.lua

@@ -1,7 +1,9 @@
 -- Common sample initialization as a framework for all samples.
 -- Common sample initialization as a framework for all samples.
 --    - Create Urho3D logo at screen
 --    - Create Urho3D logo at screen
+--    - Set custom window title and icon
 --    - Create Console and Debug HUD, and use F1 and F2 key to toggle them
 --    - Create Console and Debug HUD, and use F1 and F2 key to toggle them
 --    - Toggle rendering options from the keys 1-8
 --    - Toggle rendering options from the keys 1-8
+--    - Take screenshots with key 9
 --    - Handle Esc key down to hide Console or exit application
 --    - Handle Esc key down to hide Console or exit application
 
 
 local logoSprite = nil
 local logoSprite = nil
@@ -9,7 +11,10 @@ local logoSprite = nil
 function SampleStart()
 function SampleStart()
     -- Create logo
     -- Create logo
     CreateLogo()
     CreateLogo()
-    
+
+    -- Set custom window Title & Icon
+    SetWindowTitleAndIcon()
+
     -- Create console and debug HUD
     -- Create console and debug HUD
     CreateConsoleAndDebugHud()
     CreateConsoleAndDebugHud()
 
 
@@ -60,6 +65,14 @@ function CreateLogo()
     logoSprite.priority = -100
     logoSprite.priority = -100
 end
 end
 
 
+function SetWindowTitleAndIcon()
+    local cache = GetCache()
+    local graphics = GetGraphics()
+    local icon = cache:GetResource("Image", "Textures/LogoLarge.png")
+    graphics:SetWindowIcon(icon)
+    graphics.windowTitle = "Urho3D Sample"
+end
+
 function CreateConsoleAndDebugHud()
 function CreateConsoleAndDebugHud()
     -- Get default style
     -- Get default style
     local cache = GetCache()
     local cache = GetCache()
@@ -159,6 +172,15 @@ function HandleKeyDown(eventType, eventData)
         -- Instancing
         -- Instancing
         elseif key == KEY_8 then
         elseif key == KEY_8 then
             renderer.dynamicInstancing = not renderer.dynamicInstancing
             renderer.dynamicInstancing = not renderer.dynamicInstancing
+        
+        -- Take screenshot
+        elseif key == KEY_9 then
+            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
         end
         end
     end
     end
 end
 end