/Graphics/OpenTK/OpenTKScreenshotCapturer.cs
C# | 47 lines | 36 code | 4 blank | 7 comment | 2 complexity | 07c1572c9d0d5eda961cdd9a449b6fce MD5 | raw file
Possible License(s): Apache-2.0
- using System;
- using Delta.Engine;
- using Delta.Platforms.Windows;
- using Delta.Utilities;
- using OpenTK.Graphics.OpenGL;
-
- namespace Delta.Graphics.OpenTK
- {
- /// <summary>
- /// OpenTK Screenshot Capturer implementation
- /// </summary>
- internal class OpenTKScreenshotCapturer : ScreenshotCapturer
- {
- #region MakeScreenshot (Public)
- /// <summary>
- /// Make screenshot
- /// http://www.bit-101.com/blog/?p=1861
- /// </summary>
- public override string MakeScreenshot()
- {
- if (CapturingAllowed == false)
- {
- return null;
- }
-
- try
- {
- int width = Application.Window.ViewportPixelWidth;
- int height = Application.Window.ViewportPixelHeight;
- byte[] rgbData = new byte[width * height * 3];
- GL.ReadPixels(0, 0, width, height, PixelFormat.Rgb,
- PixelType.UnsignedByte, rgbData);
-
- string filename = GetNextFilename();
- BitmapHelper.SaveJpg(width, height, filename, rgbData, true);
- return filename;
- }
- catch (Exception ex)
- {
- Log.Info("Failed to save Screenshot: " + ex);
- }
-
- return null;
- }
- #endregion
- }
- }