/// <summary> /// Make screenshot /// </summary> private void MakeScreenshot() { try { //NOTE: This doesn't always work on all cards, especially if // desktop mode switches in fullscreen mode! screenshotNum++; // Make sure screenshots directory exists if (Directory.Exists(Directories.ScreenshotsDirectory) == false) Directory.CreateDirectory(Directories.ScreenshotsDirectory); using (Texture2D dstTexture = new Texture2D( BaseGame.Device, BaseGame.Width, BaseGame.Height, 1, ResourceUsage.ResolveTarget, SurfaceFormat.Color, ResourceManagementMode.Manual)) { // Get data with help of the resolve method BaseGame.Device.ResolveBackBuffer(dstTexture); dstTexture.Save( ScreenshotNameBuilder(screenshotNum), ImageFileFormat.Jpg); } // using } // try catch (Exception ex) { Log.Write("Failed to save Screenshot: " + ex.ToString()); } // catch (ex) }
public void DumpPickingBuffer_DEBUG(string path, ImageFileFormat format) { Texture2D tex = new Texture2D(base.ScreenMgr.GraphicsDevice, 800, 600); Color[] clrs = new Color[800 * 600]; for (int i = 0; i < 800; i++) for (int j = 0; j < 600; j++) clrs[i * 600 + j] = myPickingTexture[i, j]; tex.SetData<Color>(clrs); tex.Save(path, format); }
private void DrawReflectionMap() { Vector3 planeNormalDirection = new Vector3( 0, 1, 0 ); planeNormalDirection.Normalize(); Vector4 planeCoefficients = new Vector4( planeNormalDirection, -waterHeight ); Matrix camMatrix = camera.reflectionView * camera.projection; Matrix invCamMatrix = Matrix.Invert( camMatrix ); invCamMatrix = Matrix.Transpose( invCamMatrix ); planeCoefficients = Vector4.Transform( planeCoefficients, invCamMatrix ); Plane reflectionClipPlane = new Plane( planeCoefficients ); graphics.GraphicsDevice.ClipPlanes[ 0 ].Plane = reflectionClipPlane; graphics.GraphicsDevice.ClipPlanes[ 0 ].IsEnabled = true; graphics.GraphicsDevice.SetRenderTarget( 0, reflectionRenderTarg ); graphics.GraphicsDevice.Clear( ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0 ); if( skybox != null ) skybox.Draw( camera.reflectionView, camera.projection ); if( heightmap != null ) heightmap.Draw( camera.reflectionView, camera.projection ); graphics.GraphicsDevice.SetRenderTarget( 0, null ); reflectionMap = reflectionRenderTarg.GetTexture(); graphics.GraphicsDevice.ClipPlanes[ 0 ].IsEnabled = false; if( bSaveReflection ) { reflectionMap.Save( "reflectionMap.jpg", ImageFileFormat.Jpg ); Editor.console.Add( "Reflection jpeg saved." ); bSaveReflection = false; } }
public void GenerateSpriteSheet(int width, int height, int safeBorderSize, String outputPath, String sheetName) { if (checkBoxPowerOf2.Checked == true) { // if not a power of 2 already if ((width & (width - 1)) != 0) { width = GetNextPowerOf2(width); } if ((height & (height - 1)) != 0) { height = GetNextPowerOf2(height); } } bool overrideTransColor = checkBoxOverrideBaseColor.Checked; XnaColor baseColor = XnaColor.Black; if (overrideTransColor == true) { baseColor = new XnaColor(this.BaseTextureColor.R, this.BaseTextureColor.G, this.BaseTextureColor.B, 0); } uint[] destinationData = new uint[width * height]; for (int i = 0; i < destinationData.Length; i++) { destinationData[i] = baseColor.PackedValue; } Texture2D spriteSheet = new Texture2D(IceCream.Drawing.DrawingManager.GraphicsDevice, width, height); foreach (SpriteInfo sprite in this.Sprites) { Texture2D source = sprite.Texture2D; int x = sprite.X; int y = sprite.Y; int w = source.Width; int h = source.Height; int b = safeBorderSize; int sourceSize = sprite.Texture2D.Width; int destSize = width; // Copy the main sprite data to the output sheet. sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, 0, w, h), ref destinationData, destSize, new Point(x + b, y + b), baseColor.PackedValue, overrideTransColor); // Copy a border strip from each edge of the sprite, creating // a padding area to avoid filtering problems if the // sprite is scaled or rotated. for (int i = 0; i < safeBorderSize; i++) { sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, 0, 1, h), ref destinationData, destSize, new Point(x + i, y + b), baseColor.PackedValue, overrideTransColor); sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(w - 1, 0, 1, h), ref destinationData, destSize, new Point(x + w + i + b, y + b), baseColor.PackedValue, overrideTransColor); sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, 0, w, 1), ref destinationData, destSize, new Point(x + b, y + i), baseColor.PackedValue, overrideTransColor); sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, h - 1, w, 1), ref destinationData, destSize, new Point(x + b, y + h + i + b), baseColor.PackedValue, overrideTransColor); // Copy a single pixel from each corner of the sprite, // filling in the corners of the padding area. for (int j = 0; j < b; j++) { sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, 0, 1, 1), ref destinationData, destSize, new Point(x + j, y + i), baseColor.PackedValue, overrideTransColor); sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, 0, 1, 1), ref destinationData, destSize, new Point(x + i, y + j), baseColor.PackedValue, overrideTransColor); sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(w - 1, 0, 1, 1), ref destinationData, destSize, new Point(x + w + b + i, y + j), baseColor.PackedValue, overrideTransColor); sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(w - 1, 0, 1, 1), ref destinationData, destSize, new Point(x + w + b + j, y + i), baseColor.PackedValue, overrideTransColor); sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, h - 1, 1, 1), ref destinationData, destSize, new Point(x + i, y + h + b + j), baseColor.PackedValue, overrideTransColor); sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(0, h - 1, 1, 1), ref destinationData, destSize, new Point(x + j, y + h + b + i), baseColor.PackedValue, overrideTransColor); sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(w - 1, h - 1, 1, 1), ref destinationData, destSize, new Point(x + w + b + i, y + h + b + j), baseColor.PackedValue, overrideTransColor); sprite.CopyPixels(sprite.PixelData, sourceSize, new Rectangle(w - 1, h - 1, 1, 1), ref destinationData, destSize, new Point(x + w + b + j, y + h + b + i), baseColor.PackedValue, overrideTransColor); } } sprite.Area = new Rectangle(x + safeBorderSize, y + safeBorderSize, sprite.Texture2D.Width, sprite.Texture2D.Height); } if (checkBoxAlphaCorrection.Checked == true) { CorrectAlphaBorders(destinationData, width, height, 2); } spriteSheet.SetData<uint>(destinationData); ImageFileFormat format = (ImageFileFormat)comboBoxFileFormat.SelectedIndex; String outputFilename = Path.Combine(outputPath, sheetName + "." + format.ToString().ToLowerInvariant()); spriteSheet.Save(outputFilename, format); ExportXML(Path.Combine(outputPath, sheetName + ".xml")); }