Exemple #1
0
        /// <summary>
        /// captures and saves the screen of the current graphics device
        /// </summary>
        /// <param name="graphicsDevice"></param>
        public void saveScreenShot(GraphicsDevice graphicsDevice, GameTime time)
        {
            RenderTarget2D render = new RenderTarget2D(graphicsDevice,
                                                       graphicsDevice.PresentationParameters.BackBufferWidth,
                                                       graphicsDevice.PresentationParameters.BackBufferHeight);

            graphicsDevice.SetRenderTarget(render);

            Draw(time);

            graphicsDevice.SetRenderTarget(null);

            string     timestamp = "" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second;
            FileStream fs        = null;

            try
            {
                fs = new FileStream("screenshot_" + timestamp + ".png", FileMode.Create);

                render.SaveAsJpeg(fs, render.Width, render.Height);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("ERROR: could not create screenshot:\n" + e.ToString());
                return;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Exemple #2
0
        public override byte[] ScreenShot(GraphicsDevice graphicsDevice, RenderTarget2D screenshot)
        {
            graphicsDevice.SetRenderTarget(null);
            byte[] shot = null;
            using (MemoryStream ms = new MemoryStream())
            {
                screenshot.SaveAsJpeg(ms, screenshot.Width, screenshot.Height);
                screenshot.Dispose();
                shot = ms.ToArray(); //.GetBuffer();
            }
            //screenshot = new RenderTarget2D(graphicsDevice, 800, 480, false, SurfaceFormat.Color, DepthFormat.None);
            //screenshot = new RenderTarget2D(Season.GraphicsDevice, Season.GraphicsDevice.Viewport.Width, Season.GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);
            return(shot);
//            return null;
//            graphics.GraphicsDevice.SetRenderTarget(null);
//            byte[] shot = null;
//            using (MemoryStream ms = new MemoryStream())
//            {
//                screenshot.SaveAsJpeg(ms, screenshot.Width, screenshot.Height);
//                screenshot.Dispose();
//                shot = ms.ToArray(); //.GetBuffer();
//                screenshot = new RenderTarget2D(graphics.GraphicsDevice, 800, 480, false, SurfaceFormat.Color, DepthFormat.None);
//            }
//            return shot;
        }
        private void DrawShadow()
        {
            device.SetRenderTarget(shadowMap);
            //device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0);


            RasterizerState rs = new RasterizerState();

            rs.CullMode            = CullMode.CullClockwiseFace;
            device.RasterizerState = rs;

            device.DepthStencilState = DepthStencilState.Default;
            device.BlendState        = BlendState.Opaque;

            shadowMapEffect.CurrentTechnique = shadowMapEffect.Techniques["ShadowMap"];

            shadowMapEffect.Parameters["xWorld"].SetValue(terrain.worldPosition);
            shadowMapEffect.Parameters["xView"].SetValue(cam.shadowViewMatrix);
            shadowMapEffect.Parameters["xProjection"].SetValue(cam.shadowProjectionMatrix);

            shadowMapEffect.CurrentTechnique.Passes["Pass0"].Apply();

            terrain.DrawForShadowMap();

            device.SetRenderTarget(null);

            if (Keyboard.GetState().IsKeyDown(Keys.Back))
            {
                System.IO.Stream s = System.IO.File.OpenWrite("shadowmap.jpg");
                shadowMap.SaveAsJpeg(s, shadowMap.Width, shadowMap.Height);
                s.Close();
            }
        }
Exemple #4
0
    public void SaveCurrentImage(string jpgFilename)
    {
        GraphicsDevice.SetRenderTarget(null);
        int w = GraphicsDevice.PresentationParameters.BackBufferWidth;
        int h = GraphicsDevice.PresentationParameters.BackBufferHeight;

        using (Stream stream = new FileStream(jpgFilename, FileMode.Create))
        {
            _renderTarget.SaveAsJpeg(stream, w, h);
        }
        GraphicsDevice.SetRenderTarget(_renderTarget);
    }
Exemple #5
0
        private void SaveFrame(RenderTarget2D r, string path, string name)
        {
            //GraphicsDevice.Clear(Color.White);

            DrawSceneToTexture(renderTarget, path);

            Stream stream = File.Create(Config.OutputPath + "\\Frames\\" + name);

            //Save as PNG
            renderTarget.SaveAsJpeg(stream, 1920, 1080);
            stream.Dispose();
        }
Exemple #6
0
        private static void TakeScreenshot()
        {
            int    count = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "/", "ndump*.bmp").Length + 1;
            string name  = "/ndump" + count.ToString("000") + ".bmp";

            FileStream fileStream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "/" + name, FileMode.Create);

            screenshot.SaveAsJpeg(fileStream, Device.PresentationParameters.BackBufferWidth, Device.PresentationParameters.BackBufferHeight);
            fileStream.Close();

            //MessageRenderer.Instance.PostHeaderMessage("Screenshot dumped to " + name, 3);
        }
Exemple #7
0
        private void SaveFrame(RenderTarget2D r, string path, string name)
        {
            GraphicsDevice.Clear(Color.White);

            DrawSceneToTexture(renderTarget, path);

            Stream stream = File.Create(Config.OutputPath + "\\Frames\\" + name);

            //Save as PNG
            renderTarget.SaveAsJpeg(stream, (int)OutputWindowSize.X + LegendSize, (int)OutputWindowSize.Y);
            stream.Dispose();
        }
        public void ScreenShot()
        {
            try
            {
                int    index = 0;
                string name  = "Screenshot" + index + ".png";
                while (File.Exists(name))
                {
                    index++;
                    name = "Screenshot" + index + ".jpg";
                }

                using (FileStream stream = new FileStream(name, FileMode.Create))
                {
                    canvas.SaveAsJpeg(stream, canvas.Width, canvas.Height);
                }
                Console.WriteLine($"created Screenshot: {name}");
            } catch (Exception) { }
        }
        public static void surface_save(RenderTarget2D surface, string fname, ImageFormat format = ImageFormat.Png)
        {
            if (format == ImageFormat.Png)
            {
                if (File.Exists(fname + ".png"))
                {
                    File.SetAttributes(fname + ".png", FileAttributes.Normal);
                    File.Delete(fname + ".png");
                }

                Stream stream = File.Create(fname + ".png");
                surface.SaveAsPng(stream, surface.Width, surface.Height);
                stream.Close();
            }
            else
            {
                Stream stream = File.Create(fname + ".jpg");
                surface.SaveAsJpeg(stream, surface.Width, surface.Height);
                stream.Close();
            }
        }
Exemple #10
0
        private void createEnvMapping()
        {
            C3DRenderable model     = null;
            CTransform    transform = null;

            foreach (var component in Game1.Inst.Scene.GetComponents <C3DRenderable>())
            {
                var key = component.Key;
                model = (C3DRenderable)component.Value;
                if (model.effect == null)
                {
                    continue;
                }
                transform = (CTransform)Game1.Inst.Scene.GetComponentFromEntity <CTransform>(key);
            }
            RenderTarget2D renderTarget = new RenderTarget2D(Game1.Inst.GraphicsDevice, 256, 256);

            Game1.Inst.GraphicsDevice.Clear(Color.Black);
            Matrix view = Matrix.Identity;

            for (int i = 0; i < 6; i++)
            {
                // render the scene to all cubemap faces
                CubeMapFace cubeMapFace = (CubeMapFace)i;

                switch (cubeMapFace)
                {
                case CubeMapFace.NegativeX:
                {
                    view = Matrix.CreateLookAt(transform.Position, Vector3.Left, Vector3.Up);
                    break;
                }

                case CubeMapFace.NegativeY:
                {
                    view = Matrix.CreateLookAt(transform.Position, Vector3.Down, Vector3.Forward);
                    break;
                }

                case CubeMapFace.NegativeZ:
                {
                    view = Matrix.CreateLookAt(transform.Position, Vector3.Backward, Vector3.Up);
                    break;
                }

                case CubeMapFace.PositiveX:
                {
                    view = Matrix.CreateLookAt(transform.Position, Vector3.Right, Vector3.Up);
                    break;
                }

                case CubeMapFace.PositiveY:
                {
                    view = Matrix.CreateLookAt(transform.Position, Vector3.Up, Vector3.Backward);
                    break;
                }

                case CubeMapFace.PositiveZ:
                {
                    view = Matrix.CreateLookAt(transform.Position, Vector3.Forward, Vector3.Up);
                    break;
                }
                }

                // Set the cubemap render target, using the selected face
                Game1.Inst.GraphicsDevice.SetRenderTarget(renderTarget);
                Game1.Inst.GraphicsDevice.Clear(Color.White);
                drawNormal(view);
                //skysystem.DrawOnRequest(view);

                Color[] colordata = new Color[256 * 256];
                renderTarget.GetData(colordata);
                model.environmentMap.SetData((CubeMapFace)i, colordata);
                //DEBUG
                Stream stream = File.Create("test" + i + ".jpg");
                renderTarget.SaveAsJpeg(stream, 256, 256);
                stream.Dispose();
                // restore our matrix after changing during the cube map rendering
                //view = Matrix.CreateLookAt(new Vector3(0, 0, 0), Vector3.Zero, Vector3.Up);
            }
            Game1.Inst.GraphicsDevice.SetRenderTarget(null);
        }