PageRenderTime 164ms CodeModel.GetById 159ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/Graphics/OpenTK/OpenTKScreenshotCapturer.cs

#
C# | 47 lines | 36 code | 4 blank | 7 comment | 2 complexity | 07c1572c9d0d5eda961cdd9a449b6fce MD5 | raw file
 1using System;
 2using Delta.Engine;
 3using Delta.Platforms.Windows;
 4using Delta.Utilities;
 5using OpenTK.Graphics.OpenGL;
 6
 7namespace Delta.Graphics.OpenTK
 8{
 9	/// <summary>
10	/// OpenTK Screenshot Capturer implementation
11	/// </summary>
12	internal class OpenTKScreenshotCapturer : ScreenshotCapturer
13	{
14		#region MakeScreenshot (Public)
15		/// <summary>
16		/// Make screenshot
17		/// http://www.bit-101.com/blog/?p=1861
18		/// </summary>
19		public override string MakeScreenshot()
20		{
21			if (CapturingAllowed == false)
22			{
23				return null;
24			}
25
26			try
27			{
28				int width = Application.Window.ViewportPixelWidth;
29				int height = Application.Window.ViewportPixelHeight;
30				byte[] rgbData = new byte[width * height * 3];
31				GL.ReadPixels(0, 0, width, height, PixelFormat.Rgb,
32					PixelType.UnsignedByte, rgbData);
33
34				string filename = GetNextFilename();
35				BitmapHelper.SaveJpg(width, height, filename, rgbData, true);
36				return filename;
37			}
38			catch (Exception ex)
39			{
40				Log.Info("Failed to save Screenshot: " + ex);
41			}
42
43			return null;
44		}
45		#endregion
46	}
47}