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.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.reloadShadersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.reloadShadersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.uVViewerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.uVViewerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.createScreenshotToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.stPanel1.SuspendLayout();
|
this.stPanel1.SuspendLayout();
|
||||||
this.stContextMenuStrip1.SuspendLayout();
|
this.stContextMenuStrip1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -186,7 +187,8 @@
|
|||||||
this.resetCameraToolStripMenuItem,
|
this.resetCameraToolStripMenuItem,
|
||||||
this.modeToolStripMenuItem1,
|
this.modeToolStripMenuItem1,
|
||||||
this.projectionToolStripMenuItem,
|
this.projectionToolStripMenuItem,
|
||||||
this.orientationToolStripMenuItem});
|
this.orientationToolStripMenuItem,
|
||||||
|
this.createScreenshotToolStripMenuItem});
|
||||||
this.cameraToolStripMenuItem1.Name = "cameraToolStripMenuItem1";
|
this.cameraToolStripMenuItem1.Name = "cameraToolStripMenuItem1";
|
||||||
this.cameraToolStripMenuItem1.Size = new System.Drawing.Size(60, 20);
|
this.cameraToolStripMenuItem1.Size = new System.Drawing.Size(60, 20);
|
||||||
this.cameraToolStripMenuItem1.Text = "Camera";
|
this.cameraToolStripMenuItem1.Text = "Camera";
|
||||||
@ -226,14 +228,14 @@
|
|||||||
// orbitToolStripMenuItem
|
// orbitToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.orbitToolStripMenuItem.Name = "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.Text = "Orbit";
|
||||||
this.orbitToolStripMenuItem.Click += new System.EventHandler(this.orbitToolStripMenuItem_Click);
|
this.orbitToolStripMenuItem.Click += new System.EventHandler(this.orbitToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// walkToolStripMenuItem
|
// walkToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.walkToolStripMenuItem.Name = "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.Text = "Walk";
|
||||||
this.walkToolStripMenuItem.Click += new System.EventHandler(this.walkToolStripMenuItem_Click);
|
this.walkToolStripMenuItem.Click += new System.EventHandler(this.walkToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
@ -249,14 +251,14 @@
|
|||||||
// orthographicToolStripMenuItem
|
// orthographicToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.orthographicToolStripMenuItem.Name = "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.Text = "Orthographic";
|
||||||
this.orthographicToolStripMenuItem.Click += new System.EventHandler(this.orthographicToolStripMenuItem_Click);
|
this.orthographicToolStripMenuItem.Click += new System.EventHandler(this.orthographicToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// perspectiveToolStripMenuItem
|
// perspectiveToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.perspectiveToolStripMenuItem.Name = "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.Text = "Perspective";
|
||||||
this.perspectiveToolStripMenuItem.Click += new System.EventHandler(this.perspectiveToolStripMenuItem_Click);
|
this.perspectiveToolStripMenuItem.Click += new System.EventHandler(this.perspectiveToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
@ -344,6 +346,13 @@
|
|||||||
this.uVViewerToolStripMenuItem.Text = "UV Viewer";
|
this.uVViewerToolStripMenuItem.Text = "UV Viewer";
|
||||||
this.uVViewerToolStripMenuItem.Click += new System.EventHandler(this.uVViewerToolStripMenuItem_Click);
|
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
|
// Viewport
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
@ -398,5 +407,6 @@
|
|||||||
private System.Windows.Forms.ToolStripMenuItem walkToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem walkToolStripMenuItem;
|
||||||
private System.Windows.Forms.ToolStripMenuItem projectionToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem projectionToolStripMenuItem;
|
||||||
private System.Windows.Forms.ToolStripMenuItem walkToolStripMenuItem1;
|
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()
|
private void UpdateCameraMovement()
|
||||||
{
|
{
|
||||||
if (orbitToolStripMenuItem.Checked)
|
if (orbitToolStripMenuItem.Checked)
|
||||||
@ -646,5 +679,9 @@ namespace Toolbox.Library
|
|||||||
private void orbitToolStripMenuItem_Click(object sender, EventArgs e) {
|
private void orbitToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||||
UpdateCameraMovement();
|
UpdateCameraMovement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createScreenshotToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||||
|
SaveScreenshot();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,19 @@ namespace Toolbox.Library
|
|||||||
return Bmp;
|
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)
|
public static List<byte[]> GenerateMipMaps(Bitmap bitmap)
|
||||||
{
|
{
|
||||||
List<byte[]> datas = new List<byte[]>();
|
List<byte[]> datas = new List<byte[]>();
|
||||||
|
@ -45,10 +45,6 @@ namespace Toolbox.Library.Rendering
|
|||||||
GraphicsContext.ShareContexts = true;
|
GraphicsContext.ShareContexts = true;
|
||||||
var control = new OpenTK.GLControl();
|
var control = new OpenTK.GLControl();
|
||||||
control.MakeCurrent();
|
control.MakeCurrent();
|
||||||
// dummyResourceWindow = CreateGameWindowContext();
|
|
||||||
|
|
||||||
if (Runtime.enableOpenTKDebugOutput)
|
|
||||||
EnableOpenTKDebugOutput();
|
|
||||||
|
|
||||||
RenderTools.LoadTextures();
|
RenderTools.LoadTextures();
|
||||||
GetOpenGLSystemInfo();
|
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)
|
private static void DebugCallback(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr message, IntPtr userParam)
|
||||||
{
|
{
|
||||||
string debugMessage = Marshal.PtrToStringAnsi(message, length);
|
string debugMessage = Marshal.PtrToStringAnsi(message, length);
|
||||||
|
@ -99,12 +99,14 @@ namespace Toolbox
|
|||||||
|
|
||||||
OpenTKSharedResources.InitializeSharedResources();
|
OpenTKSharedResources.InitializeSharedResources();
|
||||||
|
|
||||||
Runtime.OpenTKInitialized = true;
|
if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Initialized)
|
||||||
|
{
|
||||||
Runtime.renderer = GL.GetString(StringName.Renderer);
|
Runtime.OpenTKInitialized = true;
|
||||||
Runtime.openGLVersion = GL.GetString(StringName.Version);
|
Runtime.renderer = GL.GetString(StringName.Renderer);
|
||||||
Runtime.GLSLVersion = GL.GetString(StringName.ShadingLanguageVersion);
|
Runtime.openGLVersion = GL.GetString(StringName.Version);
|
||||||
ParseGLVersion();
|
Runtime.GLSLVersion = GL.GetString(StringName.ShadingLanguageVersion);
|
||||||
|
ParseGLVersion();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadPLugins();
|
LoadPLugins();
|
||||||
|
Loading…
Reference in New Issue
Block a user