当前位置: 首页>>代码示例>>C#>>正文


C# RenderTarget2D.Dispose方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.RenderTarget2D.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTarget2D.Dispose方法的具体用法?C# RenderTarget2D.Dispose怎么用?C# RenderTarget2D.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Graphics.RenderTarget2D的用法示例。


在下文中一共展示了RenderTarget2D.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BasicLightableScene

        public BasicLightableScene(Graphics.Graphics graphics)
        {
            int width, height;
            width = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width;
            height = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height;

            Camera = new Camera2D();

            LightScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice,
                width, height);
            BaseScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice,
                width, height);

            _Entities = new List<IAnimatedEntity>();
            _StaticLights = new List<LightSource>();

            if (!Minecraft2D.ScaleGame)
            {
                graphics.ResolutionChanged += (sender, e) =>
                {
                    Console.WriteLine("[BasicLightableScene] Destroying and recreating render targets.");

                    width = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width;
                    height = graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height;
                    LightScene.Dispose();
                    BaseScene.Dispose();

                    LightScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice,
                        width, height);
                    BaseScene = new RenderTarget2D(graphics.GetGraphicsDeviceManager().GraphicsDevice,
                        width, height);
                };
            }
        }
开发者ID:Luigifan,项目名称:Minecraft2D,代码行数:34,代码来源:BasicLightableScene.cs

示例2: FromText

        public static Texture2D FromText(string text, SpriteFont font, Color color, Size size, bool multiLine, int lineStart, GraphicsDevice device)
        {
            string[] drawAbleText = multiLine ? text.Split(new string[1] { "\n" }, StringSplitOptions.None) : new string[1] { text };
            RenderTarget2D target = new RenderTarget2D(device, size.Width, size.Height);
            SpriteBatch sb = new SpriteBatch(device);

            device.SetRenderTarget(target);
            device.Clear(Color.Transparent);

            sb.Begin();
            for (int i = lineStart; i < drawAbleText.Length; i++)
            {
                float y = 1 + (i - lineStart) * font.GetHeight();
                sb.DrawString(font, drawAbleText[i], new Vector2(1, y), color, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            }
            sb.End();

            device.SetRenderTarget(null);

            Texture2D texture = new Texture2D(device, size.Width, size.Height);
            Color[] colorData = target.GetColorData();
            texture.SetData(colorData);

            target.Dispose();
            sb.Dispose();

            return texture;
        }
开发者ID:MentulaGames,项目名称:XnaGuiItems,代码行数:28,代码来源:Drawing.cs

示例3: LeakRepro

        void LeakRepro()
        {
            for (int i = 0; i < 50; i++)
            {
                var rt = new RenderTarget2D(
                    GraphicsDevice,
                    800, 480,
                    false, SurfaceFormat.Color,
                    DepthFormat.None, 0,
                    RenderTargetUsage.PreserveContents);
                GraphicsDevice.SetRenderTarget(rt);
                GraphicsDevice.Clear(Color.Green);
                GraphicsDevice.SetRenderTarget(null);

                MemoryStream ms = new MemoryStream();
                rt.SaveAsPng(ms, 800, 480);
                ms.Close();
                rt.Dispose();
            }
            GC.Collect();
            List<string> buttons = new List<string>();
            buttons.Add("Close");
            var message = string.Format(
                "Total memory: {0}\n" +
                "Used memory: {1}\n",
                DeviceExtendedProperties.GetValue("DeviceTotalMemory").ToString(),
                DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage").ToString()
                );
            IAsyncResult ar = Guide.BeginShowMessageBox("Info",
                message,
                buttons, 0,
                MessageBoxIcon.None, null, null);
            Guide.EndShowMessageBox(ar);
        }
开发者ID:pavlik-y,项目名称:Scratch,代码行数:34,代码来源:Game1.cs

示例4: UpdateCustomRenderTarget

        public RenderTarget2D UpdateCustomRenderTarget(RenderTarget2D renderTarget, IGameContext gameContext, SurfaceFormat? surfaceFormat, DepthFormat? depthFormat, int? multiSampleCount)
        {
            if (IsCustomRenderTargetOutOfDate(renderTarget, gameContext, surfaceFormat, depthFormat, multiSampleCount))
            {
                if (renderTarget != null)
                {
                    renderTarget.Dispose();
                }

                if (gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth == 0 &&
                    gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight == 0)
                {
                    return null;
                }

                renderTarget = new RenderTarget2D(
                    gameContext.Graphics.GraphicsDevice,
                    gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
                    gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight,
                    false,
                    surfaceFormat ?? gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferFormat,
                    depthFormat ?? gameContext.Graphics.GraphicsDevice.PresentationParameters.DepthStencilFormat,
                    multiSampleCount ?? gameContext.Graphics.GraphicsDevice.PresentationParameters.MultiSampleCount,
                    RenderTargetUsage.PreserveContents);
            }

            return renderTarget;
        }
开发者ID:RedpointGames,项目名称:Protogame,代码行数:28,代码来源:DefaultRenderTargetBackBufferUtilities.cs

示例5: BitmapFromDevice

        // Get Bitmap screenshot of specified XNA device
        public static Bitmap BitmapFromDevice( GraphicsDevice device )
        {
            PresentationParameters pp = device.PresentationParameters;

            // get texture out of XNA device first
            RenderTarget2D  deviceTexture = new RenderTarget2D( device,
                device.PresentationParameters.BackBufferWidth,
                device.PresentationParameters.BackBufferHeight,
                false, device.PresentationParameters.BackBufferFormat,
                pp.DepthStencilFormat );
            device.SetRenderTarget( deviceTexture );

            // convert texture to bitmap
            Bitmap bitmap = BitmapFromTexture( deviceTexture );

            deviceTexture.Dispose( );

            return bitmap;
        }
开发者ID:forkbomb,项目名称:pikto,代码行数:20,代码来源:Tools.cs

示例6: Draw

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            #region Set up screenshots
            if (isScreenshot)
            {
                Color[] screenData = new Color[GraphicsDevice.PresentationParameters.BackBufferWidth *
                                           GraphicsDevice.PresentationParameters.BackBufferHeight];

                screenShot = new RenderTarget2D(GraphicsDevice,
                    GraphicsDevice.PresentationParameters.BackBufferWidth,
                    GraphicsDevice.PresentationParameters.BackBufferHeight);

                GraphicsDevice.SetRenderTarget(screenShot);

                map.Draw(spriteBatch);
                base.Draw(gameTime);

                GraphicsDevice.SetRenderTarget(null);

                //save to disk
                string fileName = DateTime.Now.ToString();
                fileName = fileName.Replace('/', '-');
                fileName = fileName.Replace(':', '-');

                Stream stream = File.OpenWrite("\\Screens\\" + fileName + ".jpg");
                screenShot.SaveAsJpeg(stream,
                                        1280,
                                        720);
                stream.Dispose();
                screenShot.Dispose();

                //reset the screenshot flag
                isScreenshot = false;
            }
            #endregion

            map.Draw(spriteBatch);
            base.Draw(gameTime);
        }
开发者ID:mrahmani,项目名称:FanmadeV2,代码行数:46,代码来源:Game1.cs

示例7: UpdateRenderTarget

        public RenderTarget2D UpdateRenderTarget(RenderTarget2D renderTarget, IGameContext gameContext)
        {
            if (IsRenderTargetOutOfDate(renderTarget, gameContext))
            {
                if (renderTarget != null)
                {
                    renderTarget.Dispose();
                }

                renderTarget = new RenderTarget2D(
                    gameContext.Graphics.GraphicsDevice,
                    gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
                    gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight,
                    false,
                    gameContext.Graphics.GraphicsDevice.PresentationParameters.BackBufferFormat,
                    gameContext.Graphics.GraphicsDevice.PresentationParameters.DepthStencilFormat);
            }

            return renderTarget;
        }
开发者ID:johnsonc,项目名称:Protogame,代码行数:20,代码来源:DefaultRenderTargetBackBufferUtilities.cs

示例8: GetParticlePositions

        // We get the destinations of our particles by drawing our font to a render target and
        // reading back which pixels were set.
        List<Vector2> GetParticlePositions(GraphicsDevice device, SpriteFont font, string text)
        {
            Vector2 size = font.MeasureString(text) + new Vector2(0.5f);
            int width = (int)size.X;
            int height = (int)size.Y;

            // Create a temporary render target and draw the font on it.
            RenderTarget2D target = new RenderTarget2D(device, width, height);
            device.SetRenderTarget(target);
            device.Clear(Color.Black);

            SpriteBatch spriteBatch = new SpriteBatch(device);
            spriteBatch.Begin();
            spriteBatch.DrawString(font, text, Vector2.Zero, Color.White);
            spriteBatch.End();

            device.SetRenderTarget(null);   // unset the render target

            // read back the pixels from the render target
            Color[] data = new Color[width * height];
            target.GetData<Color>(data);
            target.Dispose();

            // Return a list of points corresponding to pixels drawn by the font. The font size will affect the number of
            // points and the quality of the text.
            List<Vector2> points = new List<Vector2>();
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // Add all points that are lighter than 50% grey. The text is white, but due to anti-aliasing pixels
                    // on the border may be shades of grey.
                    if (data[width * y + x].R > 128)
                        points.Add(new Vector2(x, y));
                }
            }

            return points;
        }
开发者ID:Winbringer,项目名称:ParticleTextNami,代码行数:41,代码来源:ParticleText.cs

示例9: SaveScreenshot

        public void SaveScreenshot(string filename)
        {
            Color[] screenData = new Color[GraphicsDevice.PresentationParameters.BackBufferWidth * GraphicsDevice.PresentationParameters.BackBufferHeight];

            RenderTarget2D screenShot = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);

            GraphicsDevice.SetRenderTarget(screenShot);

            Draw(new GameTime());

            GraphicsDevice.SetRenderTarget(null);

            int index = 0;
            string name = string.Concat(filename, "_", index, ".jpg");
            while (File.Exists(name)) {
                index++;
                name = string.Concat(filename, "_", index, ".jpg");
            }

            using (FileStream stream = new FileStream(name, FileMode.CreateNew)) {
                screenShot.SaveAsJpeg(stream, screenShot.Width, screenShot.Height);
                screenShot.Dispose();
            }
        }
开发者ID:dotKokott,项目名称:MathFighter,代码行数:24,代码来源:MainGame.cs

示例10: GenerateTextureObjectFromPopText

        public static void GenerateTextureObjectFromPopText(out TextureObject output,int num, Color? color = null)
        {
            TextureAtlas atlas = EquestriEngine.AssetManager.GetTexture("{pop_text}") as TextureAtlas;

            string temp = "" + num;
            int width = 0, height = 0;

            for (int i = 0; i < temp.Length; i++)
            {
                var rect = atlas["num_" + temp[i]];
                width += rect.Width;
                if (rect.Height > height)
                    height = rect.Height;
            }

            RenderTarget2D _textTarget = new RenderTarget2D(Device_Ref,width,height);
            Device_Ref.SetRenderTarget(_textTarget);
            Device_Ref.Clear(color == null ? Color.Black : color.Value);

            Equestribatch batch = new Equestribatch(Device_Ref);
            batch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            int lastWidth = 0;
            for (int i = 0; i < temp.Length; i++)
            {
                batch.Draw(atlas.Texture, new Vector2(lastWidth, 0), atlas["num_" + temp[i]], Color.White);
                lastWidth += atlas["num_" + temp[i]].Width;
            }

            batch.End();

            Device_Ref.SetRenderTarget(null);

            output = EquestriEngine.AssetManager.CreateTextureObjectFromTarget("{"+temp+"}", _textTarget);

            _textTarget.Dispose();
        }
开发者ID:soljakwinever,项目名称:ElegyOfDisharmony,代码行数:36,代码来源:TextureObjectFactory.cs

示例11: texturePass

        // Texture pass
        public Texture2D texturePass(Texture2D current, Texture2D texture, LayerBlendType blendType, float scale, float multiplier, Color baseColor)
        {
            // Initialize render targets and textures
            RenderTarget2D renderTarget = new RenderTarget2D(_graphicsDevice, current.Width, current.Height);
            Texture2D result = new Texture2D(_graphicsDevice, renderTarget.Width, renderTarget.Height);
            Color[] data = new Color[renderTarget.Width * renderTarget.Height];
            for (int i = 0; i < (renderTarget.Width * renderTarget.Height); i++)
                data[i] = Color.Transparent;
            result.SetData<Color>(data);

            // Handle missing texture
            if (texture == null)
            {
                texture = new Texture2D(_graphicsDevice, renderTarget.Width, renderTarget.Height);
                texture.SetData<Color>(data);
            }

            // Initialize shader
            switch (blendType)
            {
                case LayerBlendType.Opaque:
                    _textureEffect.CurrentTechnique = _textureEffect.Techniques["opaque"];
                    break;

                case LayerBlendType.Additive:
                    _textureEffect.CurrentTechnique = _textureEffect.Techniques["additive"];
                    break;

                case LayerBlendType.Overlay:
                    _textureEffect.CurrentTechnique = _textureEffect.Techniques["overlay"];
                    break;
            }
            _textureEffect.Parameters["canvasSize"].SetValue(new Vector2(current.Width, current.Height));
            _textureEffect.Parameters["textureSize"].SetValue(new Vector2(texture.Width, texture.Height));
            _textureEffect.Parameters["scale"].SetValue(scale);
            _textureEffect.Parameters["multiplier"].SetValue(multiplier);

            // Draw
            _graphicsDevice.SetRenderTarget(renderTarget);
            _graphicsDevice.Clear(Color.Transparent);
            _graphicsDevice.Textures[1] = texture;
            _spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, _textureEffect);
            _spriteBatch.Draw(current, current.Bounds, baseColor);
            _spriteBatch.End();
            _graphicsDevice.SetRenderTarget(null);

            // Save base texture
            renderTarget.GetData<Color>(data);
            result.SetData<Color>(data);

            // Cleanup
            renderTarget.Dispose();

            return result;
        }
开发者ID:klutch,项目名称:StasisEngine,代码行数:56,代码来源:MaterialRenderer.cs

示例12: LoadAndInitialize


//.........这里部分代码省略.........
                {
                    try
                    {
                        Edges.Add(new MapEdge(edge.Attribute("name").Value, Points.Find(p => p.Name == edge.Attribute("start").Value), Points.Find(p => p.Name == edge.Attribute("end").Value)));
                    }
                    catch { }
                }

                //spawn points
                XElement spawns = root.Element("Spawns");
                if (spawns == null)
                    return;
                foreach (XElement spawn in spawns.Elements("Spawn"))
                {
                    try
                    {
                        SpawnPoints.Add(new MapSpawnPoint(spawn.Attribute("name").Value,
                                        new Vector2(float.Parse(spawn.Attribute("x").Value.Replace('.', ',')), float.Parse(spawn.Attribute("y").Value.Replace('.', ','))),
                                        float.Parse(spawn.Attribute("rot").Value.Replace('.', ',')),
                                        int.Parse(spawn.Attribute("team").Value)));
                        SpawnInUse.Add(false);
                    }
                    catch { }
                }

                //rectangles
                XElement rects = root.Element("Rects");
                if (rects == null)
                    return;
                foreach (XElement rect in rects.Elements("Rect"))
                {
                    try
                    {
                        Rects.Add(new MapRect(rect.Attribute("name").Value,
                                  new Rectangle(int.Parse(rect.Attribute("x").Value), int.Parse(rect.Attribute("y").Value), int.Parse(rect.Attribute("w").Value), int.Parse(rect.Attribute("h").Value)),
                                  float.Parse(rect.Attribute("rot").Value.Replace('.', ',')),
                                  int.Parse(rect.Attribute("originX").Value), int.Parse(rect.Attribute("originY").Value)));
                    }
                    catch { }
                }

                //clean up
                //erase edges not assigned to any sector
                for (int i = 0; i < Edges.Count; )
                {
                    if (Sectors.FindIndex(s => s.Edges.FindIndex(e => Edges[i].Name == e) != -1) == -1)
                        Edges.RemoveAt(i);
                    else
                        i++;
                }
                //erase spawns outside of every sector (spawn need to be inside of some sector for motor initialization)
                for (int i = 0; i < SpawnPoints.Count; )
                {
                    if (Sectors.FindIndex(s => s.IsInSector(SpawnPoints[i].Coords)) == -1)
                        SpawnPoints.RemoveAt(i);
                    else
                        i++;
                }

                #endregion

                #region draw map and slice it

                //draw to memory
                Texture = UIParent.defaultTextures;

                RenderTarget2D mappicture = new RenderTarget2D(game.GraphicsDevice, (int)Parameters.Size.X, (int)Parameters.Size.Y, false, SurfaceFormat.Color, DepthFormat.None, 1, RenderTargetUsage.PreserveContents);
                SpriteBatch sb = new SpriteBatch(game.GraphicsDevice);
                game.GraphicsDevice.SetRenderTarget(mappicture);
                game.GraphicsDevice.Clear(Parameters.BackColor);
                sb.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
                for (int x = 0; x < (int)(Parameters.Size.X / BackCrateTexture.Width + (Parameters.Size.X % BackCrateTexture.Width != 0 ? 1 : 0)); x++)
                    for (int y = 0; y < (int)(Parameters.Size.Y / BackCrateTexture.Height + (Parameters.Size.Y % BackCrateTexture.Height != 0 ? 1 : 0)); y++)
                        sb.Draw(Texture, new Vector2(x * BackCrateTexture.Width, y * BackCrateTexture.Height), BackCrateTexture, Parameters.BackCrateColor);
                for (int i = 0; i < Rects.Count; i++)
                    Rects[i].Draw(ref sb, Parameters.BlockingColor);
                sb.End();

                //slice map
                for (int x = 0; x < Slices.GetLength(0); x++)
                    for (int y = 0; y < Slices.GetLength(1); y++)
                    {
                        Slices[x, y] = new MapSlice(game, new Rectangle((int)(x * Parameters.Slicing.X), (int)(y * Parameters.Slicing.Y), (int)Parameters.Slicing.X, (int)Parameters.Slicing.Y));
                        game.GraphicsDevice.SetRenderTarget(Slices[x, y].picture);
                        game.GraphicsDevice.Clear(Color.Transparent);
                        sb.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
                        sb.Draw(mappicture, Vector2.Zero, Slices[x, y].PositionAndSize, Color.White);
                        sb.End();
                    }

                game.GraphicsDevice.SetRenderTarget(null);

                mappicture.Dispose();
                sb.Dispose();
                Rects.Clear();

                #endregion
            }
            catch { }
        }
开发者ID:valdemart,项目名称:Motorki,代码行数:101,代码来源:Map.cs

示例13: applyShader

        public void applyShader(SpriteBatch batch, RenderTarget2D target, Effect effect)
        {
            RenderTarget2D bufferTarget = new RenderTarget2D(GraphicsDevice, target.Width, target.Height, false, GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24);

            GraphicsDevice.SetRenderTarget(bufferTarget);
            GraphicsDevice.Clear(Color.Transparent);
            batch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, effect);
            batch.Draw(target, Vector2.Zero, Color.White);
            batch.End();

            Texture2D bufferTargetTex = bufferTarget;

            GraphicsDevice.SetRenderTarget(target);
            GraphicsDevice.Clear(Color.Black);
            batch.Begin();
            batch.Draw(bufferTargetTex, Vector2.Zero, Color.White);
            batch.End();

            GraphicsDevice.SetRenderTarget(null);
            bufferTarget.Dispose();
        }
开发者ID:2Light,项目名称:Insomnia,代码行数:21,代码来源:Game1.cs

示例14: Update

        protected override void Update(GameTime gameTime)
        {
            IM.NewState();

            currentScreen.Update();
            if (currentScreen.CanTakePhoto && RM.IsDown(InputAction.AltFire) && RM.IsPressed(InputAction.Fire))
            {
                int scale = 2;
                RenderTarget2D screenshot = new RenderTarget2D(GraphicsDevice, 800 * scale, 600 * scale, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
                GraphicsDevice.Clear(Color.Black);
                GraphicsDevice.SetRenderTarget(screenshot);
                GraphicsDevice.Clear(Color.CornflowerBlue);
                currentScreen.Draw();
                GraphicsDevice.SetRenderTarget(null);

                Color[] data = new Color[320 * 240 * scale * scale];
                screenshot.GetData<Color>(0, new Rectangle(240 * scale, 180 * scale, 320 * scale, 240 * scale), data, 0, data.Length);
                Texture2D shot = new Texture2D(GraphicsDevice, 320 * scale, 240 * scale);
                shot.SetData<Color>(data);
                Photograph pg = new Photograph(shot);
                photos.Add(pg);
                screenshot.Dispose();

                currentScreen.AddPhotoData(pg);
            }

            base.Update(gameTime);
        }
开发者ID:Frib,项目名称:LD24,代码行数:28,代码来源:G.cs

示例15: RefreshArenaRadarSilhouette

        /// <summary>
        /// Uses <see cref="GraphicsDevice"/>, so call only during <see cref="Draw"/>.
        /// </summary>
        private void RefreshArenaRadarSilhouette()
        {
            if (Game.DataEngine.Arena == null) throw new InvalidOperationException("No active arena");
            Dispose();

            // Draw arena walls in one color in a radar-sized texture.
            var gfx = Game.GraphicsDeviceService.GraphicsDevice;
            var oldViewport = gfx.Viewport;
            int targetWidth = (int)_arenaDimensionsOnRadar.X;
            int targetHeight = (int)_arenaDimensionsOnRadar.Y;
            var gfxAdapter = gfx.Adapter;
            SurfaceFormat selectedFormat;
            DepthFormat selectedDepthFormat;
            int selectedMultiSampleCount;
            gfxAdapter.QueryRenderTargetFormat(GraphicsProfile.Reach, SurfaceFormat.Color, DepthFormat.None, 1, out selectedFormat, out selectedDepthFormat, out selectedMultiSampleCount);
            var maskTarget = new RenderTarget2D(gfx, targetWidth, targetHeight, false, selectedFormat, selectedDepthFormat);

            // Set up draw matrices.
            var view = Matrix.CreateLookAt(new Vector3(0, 0, 500), Vector3.Zero, Vector3.Up);
            var projection = Matrix.CreateOrthographicOffCenter(0, Game.DataEngine.Arena.Dimensions.X,
                0, Game.DataEngine.Arena.Dimensions.Y, 10, 1000);

            // Set and clear our own render target.
            gfx.SetRenderTarget(maskTarget);
            gfx.Clear(ClearOptions.Target, Color.Transparent, 0, 0);

            // Draw the arena's walls.
            Game.GraphicsEngine.GameContent.RadarSilhouetteSpriteBatch.Begin();
            foreach (var wall in Game.DataEngine.Arena.GobsInRelevantLayers.OfType<AW2.Game.Gobs.Wall>())
                wall.DrawSilhouette(view, projection, Game.GraphicsEngine.GameContent.RadarSilhouetteSpriteBatch);
            Game.GraphicsEngine.GameContent.RadarSilhouetteSpriteBatch.End();

            // Restore render target so what we can extract drawn pixels.
            // Create a copy of the texture in local memory so that a graphics device
            // reset (e.g. when changing resolution) doesn't lose the texture.
            gfx.SetRenderTarget(null);
            gfx.Viewport = oldViewport;
            var textureData = new Color[targetHeight * targetWidth];
            maskTarget.GetData(textureData);
            ArenaRadarSilhouette = new Texture2D(gfx, targetWidth, targetHeight, false, SurfaceFormat.Color);
            ArenaRadarSilhouette.SetData(textureData);

            maskTarget.Dispose();
        }
开发者ID:vvnurmi,项目名称:assaultwing,代码行数:47,代码来源:ArenaSilhouette.cs


注:本文中的Microsoft.Xna.Framework.Graphics.RenderTarget2D.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。