Пример #1
0
        public void SaveScreenshot(string fileName)
        {
            Surface backbuffer = d3d.Dx.GetBackBuffer(0, 0, BackBufferType.Mono);

            SurfaceLoader.Save(fileName, ImageFileFormat.Jpg, backbuffer);
            backbuffer.Dispose();
        }
Пример #2
0
        public void Render2()
        {
            if (device2 == null)   //如果device为空则不渲染
            {
                return;
            }
            device2.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0);  //清除windows界面为深蓝色
            device2.BeginScene();
            {
                //在此添加渲染图形代码
                CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[4];//定义顶点
                vertices[0].Position = new Vector4(150f, 400f, 0f, 1f);
                vertices[0].Color    = Color.Yellow.ToArgb();
                vertices[1].Position = new Vector4(panel2.Width / 2, 100f, 0f, 1f);
                vertices[1].Color    = Color.Green.ToArgb();
                vertices[2].Position = new Vector4(panel2.Width - 150f, 400f, 0f, 1f);
                vertices[2].Color    = Color.Red.ToArgb();

                device2.VertexFormat = CustomVertex.TransformedColored.Format;
                device2.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);
                //截取panel2的截图
                Surface backbuffer = device2.GetBackBuffer(0, 0, BackBufferType.Mono);
                SurfaceLoader.Save("Screenshot2.bmp", ImageFileFormat.Bmp, backbuffer);
            }
            device2.EndScene();
            device2.Present();
        }
Пример #3
0
        private void HandleFileSaving()
        {
            string destination;

            // if file format is bitmap save directly to output directory
            if (renderSettings.FileFormat == FileFormat.bmp)
            {
                destination = renderSettings.FilePath + renderSettings.FileName + frameCount.ToString() + "." + renderSettings.FileFormat.ToString();
            }
            // else save to temporary directory
            else
            {
                destination = tempDirectory + "\\" + renderSettings.FileName + frameCount.ToString() + ".bmp";
            }

            // save file
            SurfaceLoader.Save(destination, ImageFileFormat.Bmp, renderSurface.RenderTarget);


            // if it as an image other than BMP do conversion
            if (renderSettings.FileFormat != FileFormat.bmp && renderSettings.FileFormat != FileFormat.avi)
            {
                DoImageFileConversion();
            }

            // increment frameCount
            ++frameCount;
        }
Пример #4
0
 public static void SaveImage(Device device, string fileName, ImageFileFormat format)
 {
     using (Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono))
     {
         SurfaceLoader.Save(fileName, format, backbuffer);
     }
 }
Пример #5
0
 /// <summary>
 /// バックバッファをPNG形式でファイルに保存します。
 /// </summary>
 /// <param name="file">ファイル名</param>
 public void SaveToPng(string file)
 {
     using (Surface sf = device.GetBackBuffer(0, 0, BackBufferType.Mono))
         if (sf != null)
         {
             SurfaceLoader.Save(file, ImageFileFormat.Png, sf);
         }
 }
Пример #6
0
        } // _KeyDown().fim

        // [---
        private void salvarImagem()
        {
            Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono);

            SurfaceLoader.Save("foto_tela.jpg", ImageFileFormat.Jpg, backbuffer);
            backbuffer.Dispose();
            this.Text = "Ok. Imagem salva no disco";
        }
Пример #7
0
 public void SaveToBitmap()
 {
     using (Surface sf = device.GetBackBuffer(0, 0, BackBufferType.Mono))
         if (sf != null)
         {
             string path = GetBitmapPath();
             string dir  = Path.GetDirectoryName(path);
             if (!Directory.Exists(dir))
             {
                 Directory.CreateDirectory(dir);
             }
             SurfaceLoader.Save(path, ImageFileFormat.Png, sf);
         }
 }
        public string SaveScreenShot(string filePath)
        {
            string file = filePath + "." + ScreenshotExtension();

            Logger.WriteLine(Logger.Stage.RUN_GFX, "taking screenshot...");
            try
            {
                SurfaceLoader.Save(filePath, ImageFileFormat.Png, m_RenderSurface);
            }
            catch (Exception e)
            {
                Logger.WriteLine(Logger.Stage.RUN_GFX, String.Format("exception when taking screenshot : {0}", e.ToString()));
                return(null);
            }
            Logger.WriteLine(Logger.Stage.RUN_GFX, "taking screenshot... done!");
            return(file);
        }
Пример #9
0
        public static void DumpScreenShot()
        {
            DirectoryInfo screenFolder = new DirectoryInfo(Application.StartupPath + "\\Screenshots\\");

            if (!screenFolder.Exists)
            {
                screenFolder.Create();
            }

            Surface backbuffer = renderer.Device.GetBackBuffer(0, 0, BackBufferType.Mono);
            string  picPath    = Application.StartupPath + "\\Screenshots\\" + DateTime.Now.Month + "-" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + ".jpg";

            SurfaceLoader.Save(picPath, ImageFileFormat.Jpg, backbuffer);
            backbuffer.Dispose();

            messageConsole.AddMessage("Screenshot saved to " + picPath);
        }
Пример #10
0
        public override void SaveTo(string frameFile, ImageFileFormat format)
        {
            Direct3D.Surface         surf      = mTexture.Value.GetSurfaceLevel(0);
            Direct3D.ImageFileFormat d3dformat = Microsoft.DirectX.Direct3D.ImageFileFormat.Png;

            switch (format)
            {
            case ImageFileFormat.Bmp: d3dformat = Direct3D.ImageFileFormat.Bmp; break;

            case ImageFileFormat.Png: d3dformat = Direct3D.ImageFileFormat.Png; break;

            case ImageFileFormat.Jpg: d3dformat = Direct3D.ImageFileFormat.Jpg; break;

            case ImageFileFormat.Tga: d3dformat = Direct3D.ImageFileFormat.Tga; break;
            }

            SurfaceLoader.Save(frameFile, d3dformat, surf, Interop.Convert(mSrcRect));
        }
Пример #11
0
        /// <summary>
        /// Take a screenshot of the current scene.
        /// </summary>
        /// <param name="path">Path to save the file to.</param>
        /// <param name="format">Texture format to save the screenshot as.</param>
        /// <param name="background">Background color.</param>
        public void screenshot(string path, ImageFileFormat format, Color background)
        {
            // Create the surface to render to.
            Surface screenshot = device.CreateRenderTarget(presentParams.BackBufferWidth, presentParams.BackBufferHeight,
                                                           Format.A8R8G8B8, MultiSampleType.None, 0, true);
            // Get the current render target.
            Surface defaultSurface = device.GetRenderTarget(0);

            // Set the screenshot surface as the render target.
            device.SetRenderTarget(0, screenshot);

            RenderScene(background);

            // Save the screenshot.
            SurfaceLoader.Save(path, format, screenshot);

            // Restore the render target.
            device.SetRenderTarget(0, defaultSurface);
        }
Пример #12
0
        private void RenderToIrradianceCubeMapFace(CubeMapFace face)
        {
            var cubeMapFace = irradianceMap.GetCubeMapSurface(face, 0);

            D3DDevice.Instance.Device.SetRenderTarget(0, cubeMapFace);

            TGCMatrix lookAt = LookAtFromCubeMapFace(face, TGCVector3.Empty);

            D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            D3DDevice.Instance.Device.Transform.View = lookAt;

            D3DDevice.Instance.Device.BeginScene();

            unitCube.Render();

            D3DDevice.Instance.Device.EndScene();

            if (save)
            {
                SurfaceLoader.Save(ShadersDir + "irradiancemap_" + face.ToString() + ".bmp", ImageFileFormat.Bmp, cubeMapFace);
            }
        }
Пример #13
0
        private void RenderToCubeMapFace(CubeMapFace face, TGCVector3 position)
        {
            var cubeMapFace = cubeMap.GetCubeMapSurface(face, 0);

            D3DDevice.Instance.Device.SetRenderTarget(0, cubeMapFace);
            D3DDevice.Instance.Device.DepthStencilSurface = depthStencils[(int)face];

            TGCMatrix lookAt = LookAtFromCubeMapFace(face, position);

            D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            D3DDevice.Instance.Device.Transform.View = lookAt;

            D3DDevice.Instance.Device.BeginScene();

            RenderBaseScene();

            D3DDevice.Instance.Device.EndScene();

            if (save)
            {
                SurfaceLoader.Save(ShadersDir + "cubemap_" + face.ToString() + ".bmp", ImageFileFormat.Bmp, cubeMapFace);
            }
        }
Пример #14
0
        /// <summary>
        /// Called once per frame, the call is the entry point for all game processing.
        /// This function calls the appropriate part of the game engine based on the
        /// current state.
        /// </summary>
        protected override void FrameMove()
        {
            try
            {
                SelectControls select_form = null;
                // get any player inputs
                m_Engine.GetPlayerInputs();

                // Clear the viewport
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, 0x00000000, 1.0f, 0);

                device.BeginScene();

                // determine what needs to be rendered based on the current game state
                switch (m_State)
                {
                case GameState.DevSplash:
                    if (m_Engine.ShowSplash(@"..\..\Resources\devsplash.jpg", 8, new BackgroundTask(LoadOptions)))
                    {
                        m_State = GameState.GameSplash;
                    }
                    break;

                case GameState.GameSplash:
                    if (m_Engine.ShowSplash(@"..\..\Resources\gamesplash.jpg", 8, null))
                    {
                        m_State     = GameState.OptionsMain;
                        select_form = new SelectControls();
                        select_form.ShowDialog(this);
                        m_bUsingJoystick = select_form.UseJoystick.Checked;
                        m_bUsingKeyboard = select_form.UseKeyboard.Checked;
                        m_bUsingMouse    = select_form.UseMouse.Checked;
                        if (m_bUsingJoystick)
                        {
                            GameEngine.Console.AddLine("Using Joystick");
                        }
                        if (m_bUsingKeyboard)
                        {
                            GameEngine.Console.AddLine("Using Keyboard");
                        }
                        if (m_bUsingMouse)
                        {
                            GameEngine.Console.AddLine("Using Mouse");
                        }
                        m_ownship             = (Ownship)Engine.GetObject("car1");
                        m_ownship.UseJoystick = m_bUsingJoystick;
                        m_ownship.UseKeyboard = m_bUsingKeyboard;
                        m_ownship.UseMouse    = m_bUsingMouse;
                    }
                    break;

                case GameState.OptionsMain:
                    m_Engine.DoOptions();
                    break;

                case GameState.GamePlay:
                    m_Engine.GetPlayerInputs();
                    m_Engine.DoAI(elapsedTime);
                    m_Engine.DoDynamics(elapsedTime);
                    m_Engine.DoNetworking(elapsedTime);
                    m_Engine.Render();
                    break;

                case GameState.AfterActionReview:
                    m_Engine.DoAfterActionReview();
                    break;
                }

                GameEngine.Console.Render();

                if (false && m_ownship != null && m_State == GameState.GamePlay)
                {
                    m_pFont.DrawText(200, 560, Color.FromArgb(255, 0, 0, 0), m_ownship.MPH.ToString());
                    m_pFont.DrawText(280, 560, Color.FromArgb(255, 0, 0, 0), m_ownship.RPM.ToString());
                    m_pFont.DrawText(200, 580, Color.FromArgb(255, 0, 0, 0), m_ownship.ForwardVelocity.ToString());
                    m_pFont.DrawText(100, 560, Color.FromArgb(255, 0, 0, 0), m_ownship.SidewaysVelocity.ToString());
                    m_pFont.DrawText(100, 580, Color.FromArgb(255, 0, 0, 0), m_ownship.Steering.ToString());
                }

                // Output statistics
                if (m_bShowStatistics)
                {
                    m_pFont.DrawText(2, 560, Color.FromArgb(255, 255, 255, 0), frameStats);
                    m_pFont.DrawText(2, 580, Color.FromArgb(255, 255, 255, 0), deviceStats);
                    m_pFont.DrawText(500, 580, Color.FromArgb(255, 255, 255, 0),
                                     m_Engine.Cam.Heading.ToString() + " " + m_Engine.Cam.Pitch.ToString() + " " +
                                     m_Engine.Cam.X + " " + m_Engine.Cam.Y + " " + m_Engine.Cam.Z);
                    m_pFont.DrawText(2, 600, Color.FromArgb(255, 255, 255, 0),
                                     "Steering " + (CGameEngine.Inputs.GetJoystickNormalX() - 1.0f).ToString() + " " +
                                     "throttle/Brake " + (1.0f - CGameEngine.Inputs.GetJoystickNormalY()).ToString());
                }

                if (m_bScreenCapture)
                {
                    SurfaceLoader.Save("capture.bmp", ImageFileFormat.Bmp, device.GetBackBuffer(0, 0, BackBufferType.Mono));
                    m_bScreenCapture = false;
                    GameEngine.Console.AddLine("snapshot taken");
                }
            }
            catch (DirectXException d3de)
            {
                System.Diagnostics.Debug.WriteLine("Error in Sample Game Application FrameMove");
                System.Diagnostics.Debug.WriteLine(d3de.ErrorString);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error in Sample Game Application FrameMove");
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
            finally
            {
                device.EndScene();
            }
        }
Пример #15
0
 public void SaveToJPEG(string pFileName)
 {
     SurfaceLoader.Save(pFileName, ImageFileFormat.Jpg, this.device.GetBackBuffer(0, 0, BackBufferType.Mono));
 }