Add option to create screenshots
This commit is contained in:
parent
77d05f47cb
commit
9e61c677ed
20
Switch_Toolbox_Library/Forms/Viewport.Designer.cs
generated
20
Switch_Toolbox_Library/Forms/Viewport.Designer.cs
generated
@ -61,6 +61,7 @@
|
||||
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.reloadShadersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.uVViewerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.createScreenshotToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.stPanel1.SuspendLayout();
|
||||
this.stContextMenuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -186,7 +187,8 @@
|
||||
this.resetCameraToolStripMenuItem,
|
||||
this.modeToolStripMenuItem1,
|
||||
this.projectionToolStripMenuItem,
|
||||
this.orientationToolStripMenuItem});
|
||||
this.orientationToolStripMenuItem,
|
||||
this.createScreenshotToolStripMenuItem});
|
||||
this.cameraToolStripMenuItem1.Name = "cameraToolStripMenuItem1";
|
||||
this.cameraToolStripMenuItem1.Size = new System.Drawing.Size(60, 20);
|
||||
this.cameraToolStripMenuItem1.Text = "Camera";
|
||||
@ -226,14 +228,14 @@
|
||||
// orbitToolStripMenuItem
|
||||
//
|
||||
this.orbitToolStripMenuItem.Name = "orbitToolStripMenuItem";
|
||||
this.orbitToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.orbitToolStripMenuItem.Size = new System.Drawing.Size(101, 22);
|
||||
this.orbitToolStripMenuItem.Text = "Orbit";
|
||||
this.orbitToolStripMenuItem.Click += new System.EventHandler(this.orbitToolStripMenuItem_Click);
|
||||
//
|
||||
// walkToolStripMenuItem
|
||||
//
|
||||
this.walkToolStripMenuItem.Name = "walkToolStripMenuItem";
|
||||
this.walkToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.walkToolStripMenuItem.Size = new System.Drawing.Size(101, 22);
|
||||
this.walkToolStripMenuItem.Text = "Walk";
|
||||
this.walkToolStripMenuItem.Click += new System.EventHandler(this.walkToolStripMenuItem_Click);
|
||||
//
|
||||
@ -249,14 +251,14 @@
|
||||
// orthographicToolStripMenuItem
|
||||
//
|
||||
this.orthographicToolStripMenuItem.Name = "orthographicToolStripMenuItem";
|
||||
this.orthographicToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.orthographicToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
|
||||
this.orthographicToolStripMenuItem.Text = "Orthographic";
|
||||
this.orthographicToolStripMenuItem.Click += new System.EventHandler(this.orthographicToolStripMenuItem_Click);
|
||||
//
|
||||
// perspectiveToolStripMenuItem
|
||||
//
|
||||
this.perspectiveToolStripMenuItem.Name = "perspectiveToolStripMenuItem";
|
||||
this.perspectiveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.perspectiveToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
|
||||
this.perspectiveToolStripMenuItem.Text = "Perspective";
|
||||
this.perspectiveToolStripMenuItem.Click += new System.EventHandler(this.perspectiveToolStripMenuItem_Click);
|
||||
//
|
||||
@ -344,6 +346,13 @@
|
||||
this.uVViewerToolStripMenuItem.Text = "UV Viewer";
|
||||
this.uVViewerToolStripMenuItem.Click += new System.EventHandler(this.uVViewerToolStripMenuItem_Click);
|
||||
//
|
||||
// createScreenshotToolStripMenuItem
|
||||
//
|
||||
this.createScreenshotToolStripMenuItem.Name = "createScreenshotToolStripMenuItem";
|
||||
this.createScreenshotToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.createScreenshotToolStripMenuItem.Text = "Create Screenshot";
|
||||
this.createScreenshotToolStripMenuItem.Click += new System.EventHandler(this.createScreenshotToolStripMenuItem_Click);
|
||||
//
|
||||
// Viewport
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@ -398,5 +407,6 @@
|
||||
private System.Windows.Forms.ToolStripMenuItem walkToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem projectionToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem walkToolStripMenuItem1;
|
||||
private System.Windows.Forms.ToolStripMenuItem createScreenshotToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -613,6 +613,39 @@ namespace Toolbox.Library
|
||||
}
|
||||
}
|
||||
|
||||
public GLControl GetActiveControl()
|
||||
{
|
||||
if (GL_ControlModern != null)
|
||||
return GL_ControlModern;
|
||||
else
|
||||
return GL_ControlLegacy;
|
||||
}
|
||||
|
||||
public void SaveScreenshot()
|
||||
{
|
||||
var control = GetActiveControl();
|
||||
|
||||
SaveFileDialog sfd = new SaveFileDialog();
|
||||
sfd.Filter = BitmapExtension.FileFilter;
|
||||
if (sfd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
CreateScreenshot(control.Width, control.Height, false).Save(sfd.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap CreateScreenshot(int width, int height, bool useAlpha = false)
|
||||
{
|
||||
int imageSize = width * height * 4;
|
||||
|
||||
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
|
||||
byte[] output = new byte[imageSize];
|
||||
GL.ReadPixels(0, 0, width, height, PixelFormat.Bgra, PixelType.UnsignedByte, output);
|
||||
|
||||
var bitmap = BitmapExtension.GetBitmap(output, width, height);
|
||||
bitmap.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private void UpdateCameraMovement()
|
||||
{
|
||||
if (orbitToolStripMenuItem.Checked)
|
||||
@ -646,5 +679,9 @@ namespace Toolbox.Library
|
||||
private void orbitToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
UpdateCameraMovement();
|
||||
}
|
||||
|
||||
private void createScreenshotToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
SaveScreenshot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,19 @@ namespace Toolbox.Library
|
||||
return Bmp;
|
||||
}
|
||||
|
||||
public static string FileFilter
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Supported Formats|*.png;*.tga;*.jpg;*.tiff|" +
|
||||
"Portable Network Graphics |*.png|" +
|
||||
"Joint Photographic Experts Group |*.jpg|" +
|
||||
"Bitmap Image |*.bmp|" +
|
||||
"Tagged Image File Format |*.tiff|" +
|
||||
"All files(*.*)|*.*";
|
||||
}
|
||||
}
|
||||
|
||||
public static List<byte[]> GenerateMipMaps(Bitmap bitmap)
|
||||
{
|
||||
List<byte[]> datas = new List<byte[]>();
|
||||
|
@ -45,10 +45,6 @@ namespace Toolbox.Library.Rendering
|
||||
GraphicsContext.ShareContexts = true;
|
||||
var control = new OpenTK.GLControl();
|
||||
control.MakeCurrent();
|
||||
// dummyResourceWindow = CreateGameWindowContext();
|
||||
|
||||
if (Runtime.enableOpenTKDebugOutput)
|
||||
EnableOpenTKDebugOutput();
|
||||
|
||||
RenderTools.LoadTextures();
|
||||
GetOpenGLSystemInfo();
|
||||
@ -63,24 +59,6 @@ namespace Toolbox.Library.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnableOpenTKDebugOutput()
|
||||
{
|
||||
#if DEBUG
|
||||
/*// This isn't free, so skip this step when not debugging.
|
||||
// TODO: Only works with Intel integrated.
|
||||
if (SFGraphics.Tools.OpenGLExtensions.IsAvailable("GL_KHR_debug"))
|
||||
{
|
||||
GL.Enable(EnableCap.DebugOutput);
|
||||
GL.Enable(EnableCap.DebugOutputSynchronous);
|
||||
debugProc = DebugCallback;
|
||||
GL.DebugMessageCallback(debugProc, IntPtr.Zero);
|
||||
int[] ids = { };
|
||||
GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare,
|
||||
DebugSeverityControl.DontCare, 0, ids, true);
|
||||
}*/
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void DebugCallback(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr message, IntPtr userParam)
|
||||
{
|
||||
string debugMessage = Marshal.PtrToStringAnsi(message, length);
|
||||
|
@ -99,12 +99,14 @@ namespace Toolbox
|
||||
|
||||
OpenTKSharedResources.InitializeSharedResources();
|
||||
|
||||
Runtime.OpenTKInitialized = true;
|
||||
|
||||
Runtime.renderer = GL.GetString(StringName.Renderer);
|
||||
Runtime.openGLVersion = GL.GetString(StringName.Version);
|
||||
Runtime.GLSLVersion = GL.GetString(StringName.ShadingLanguageVersion);
|
||||
ParseGLVersion();
|
||||
if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Initialized)
|
||||
{
|
||||
Runtime.OpenTKInitialized = true;
|
||||
Runtime.renderer = GL.GetString(StringName.Renderer);
|
||||
Runtime.openGLVersion = GL.GetString(StringName.Version);
|
||||
Runtime.GLSLVersion = GL.GetString(StringName.ShadingLanguageVersion);
|
||||
ParseGLVersion();
|
||||
}
|
||||
}
|
||||
|
||||
LoadPLugins();
|
||||
|
Loading…
Reference in New Issue
Block a user