PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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