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


C# GraphicsDevice.SetRenderTarget方法代码示例

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


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

示例1: Initialize

        protected override void Initialize()
        {
            graphics.IsFullScreen = false;
            graphics.PreferredBackBufferWidth = width;
            graphics.PreferredBackBufferHeight = height;
            graphics.ApplyChanges();
            Window.Title = "Exercise I.7";

            this.IsMouseVisible = true;

            spriteBatch = new SpriteBatch(GraphicsDevice);
            device = graphics.GraphicsDevice;
            rt = new RenderTarget2D(GraphicsDevice,
                width,
                height,
                false,
                device.PresentationParameters.BackBufferFormat,
                DepthFormat.Depth24,
                0,
                RenderTargetUsage.PreserveContents);

            device.SetRenderTarget(rt);
            device.Clear(Color.Black);
            device.SetRenderTarget(null);

            Drawing.init(device, spriteBatch);
            Stats.init();

            w = new Walker(width, height);

            base.Initialize();
        }
开发者ID:GennaroC,项目名称:CSharp-TheNatureOfCode,代码行数:32,代码来源:Game1.cs

示例2: CreateBackground

        private Texture2D CreateBackground(GraphicsDevice graphics, SpriteBatch spriteBatch, ContentManager Content)
        {
            RenderTarget2D target = new RenderTarget2D(graphics, 2048, 2048);
            //tell the GraphicsDevice we want to render to the gamesMenu rendertarget (an in-memory buffer)
            graphics.SetRenderTarget(target);

            //clear the background
            graphics.Clear(Color.Transparent);

            //begin drawing
            spriteBatch.Begin();
            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    spriteBatch.Draw(Content.Load<Texture2D>("starBackground"), new Vector2(x * 256, y * 256), Color.White);
                }
            }

            spriteBatch.End();
            //reset the GraphicsDevice to draw on the backbuffer (directly to the backbuffer)
            graphics.SetRenderTarget(null);

            return target;
        }
开发者ID:Siryu,项目名称:Asteroids,代码行数:25,代码来源:Background.cs

示例3: 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

示例4: CreateTextureAtlasAsset

        public TextureAtlasAsset CreateTextureAtlasAsset(
            string name,
            GraphicsDevice graphicsDevice,
            IEnumerable<TextureAsset> textures)
        {
            if (name == null) throw new ArgumentNullException("name");
            if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice");
            if (textures == null) throw new ArgumentNullException("textures");

            var textureArray = textures.ToArray();
            var size = this.CalculateSizeForTextures(textureArray);

            var mappings = new Dictionary<string, Rectangle>();
            var renderTarget = new RenderTarget2D(graphicsDevice, (int)size.X, (int)size.Y);

            try
            {
                var x = 0;
                var y = 0;
                graphicsDevice.SetRenderTarget(renderTarget);
                graphicsDevice.Clear(Color.Transparent);

                using (var spriteBatch = new SpriteBatch(graphicsDevice))
                {
                    spriteBatch.Begin();

                    foreach (var texture in textureArray)
                    {
                        if (texture.Texture.Width == 16 ||
                            texture.Texture.Height == 16)
                        {
                            spriteBatch.Draw(texture.Texture, new Vector2(x, y));
                            mappings.Add(texture.Name, new Rectangle(x, y, 16, 16));
                            x += 16;
                            if (x >= size.X)
                            {
                                x = 0;
                                y += 16;
                            }
                        }
                    }

                    spriteBatch.End();
                }
            }
            catch (InvalidOperationException)
            {
            }

            graphicsDevice.SetRenderTarget(null);
            graphicsDevice.BlendState = BlendState.Opaque;
            graphicsDevice.DepthStencilState = DepthStencilState.Default;
            graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
            graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

            return new TextureAtlasAsset(
                name,
                renderTarget,
                mappings);
        }
开发者ID:TreeSeed,项目名称:Tychaia,代码行数:60,代码来源:DefaultTextureAtlasAssetFactory.cs

示例5: CreateBackground

        private Texture2D CreateBackground(GraphicsDevice gd, SpriteBatch sb, ContentManager cm)
        {
            RenderTarget2D target = new RenderTarget2D(gd, 2048, 2048);
            //tell the GraphicsDevice we want to render to the gamesMenu rendertarget (an in-memory buffer)
            gd.SetRenderTarget(target);

            //clear the background
            gd.Clear(Color.Transparent);

            //begin drawing
            sb.Begin();
            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    sb.Draw(cm.Load<Texture2D>("Backgrounds/" + _level.ToString()), new Vector2(x * 400, y * 256), Color.White);
                }
            }

            sb.End();
            //reset the GraphicsDevice to draw on the backbuffer (directly to the backbuffer)
            gd.SetRenderTarget(null);

            return (Texture2D)target;
        }
开发者ID:Siryu,项目名称:Dinosaur-Laser-Assault,代码行数:25,代码来源:Background.cs

示例6: AccumulateLights

        private void AccumulateLights(IEnumerable<ILightProvider> lights, SpriteBatch sb, GraphicsDevice graphicsDevice)
        {
            graphicsDevice.SetRenderTarget(_accumulatorRT);
            graphicsDevice.Clear(Color.Black);

            foreach (var light in lights)
            {
                sb.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, _lightAccumulatorFX, GameVariables.CameraZoomMatrix);
                var normalizedPosition = new Vector2(light.Position.X / _accumulatorRT.Width,
                                                     light.Position.Y / _accumulatorRT.Height);

                _lightAccumulatorFX.Parameters["lightPosition"].SetValue(normalizedPosition);
                _lightAccumulatorFX.Parameters["lightRadius"].SetValue(light.LightRadius);
                _lightAccumulatorFX.Parameters["lightIntensity"].SetValue(light.LightIntensity);

                sb.Draw(_screenTex, new Rectangle(0, 0, _accumulatorRT.Width, _accumulatorRT.Height), Color.White);
                sb.End();
            }

            graphicsDevice.SetRenderTarget(null);

            //if (lights.Any())
            //{
            //    using (var stream = new FileStream("output.png", FileMode.OpenOrCreate))
            //    {
            //        _accumulatorRT.SaveAsPng(stream, _accumulatorRT.Width, _accumulatorRT.Height);
            //    }
            //}
        }
开发者ID:aefreedman,项目名称:Lumen,代码行数:29,代码来源:LightManager.cs

示例7: Render

 public void Render(SpriteBatch spriteBatch, GraphicsDevice Device)
 {
     Device.SetRenderTarget(this.rt2d);
     Device.Clear(Color.Transparent);
     spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, null, null);
     foreach (Enemy x in this.lxEnemies)
     {
         x.xRenderComponent.Render(spriteBatch);
     }
     foreach (RenderComponent x2 in this.lxRenderComponents)
     {
         x2.Render(spriteBatch);
     }
     spriteBatch.End();
     Device.SetRenderTarget(null);
     if (this.iFramesToRender > 0 && this.iFramesRendered < this.iFramesToRender && this.iCounter % this.iRenderStep == 0)
     {
         if (!Directory.Exists("../Slashas"))
         {
             Directory.CreateDirectory("../Slashas");
         }
         FileStream mos = new FileStream("../Slashas/0" + this.iFramesRendered + ".png", FileMode.Create, FileAccess.Write);
         this.rt2d.SaveAsPng(mos, this.rt2d.Width, this.rt2d.Height);
         mos.Close();
         this.iFramesRendered++;
         if (this.iFramesRendered == this.iFramesToRender)
         {
             this.iFramesToRender = 0;
         }
     }
 }
开发者ID:ancientgods,项目名称:SoG,代码行数:31,代码来源:TheDebugKing.cs

示例8: addarea

        public void addarea(int left, int top, int width, int height,GraphicsDevice device,SpriteBatch batch)
        {
            for (int I = left; I < left + width; I++)
            {
                for (int J = top; J < top + height; J++)
                {
                    tilearray[I, J] = new tile();
                }
            }

            RenderTarget2D target = new RenderTarget2D(device, 4096, 4096);
            device.SetRenderTarget(target);
            device.Clear(Color.Transparent);
            batch.Begin();

            for (int X = 0; X < 256; X++)
            {
                for (int Y = 0; Y < 256; Y++)
                {
                    if (tilearray[X, Y] != null)
                    {
                        batch.Draw(tiletexture, new Vector2(X*8, Y*8), Color.White);
                    }
                }
            }
            batch.End();

            tileoverlay = (Texture2D)target;

            device.SetRenderTarget(null);
            device.Clear(Color.CornflowerBlue);
        }
开发者ID:RcColes,项目名称:Space,代码行数:32,代码来源:ship.cs

示例9: LineRenderer

        public LineRenderer(GraphicsDevice graphicsDevice)
        {
            lineTexture = new RenderTarget2D(graphicsDevice, 2, 3);

            graphicsDevice.SetRenderTarget(lineTexture);
            graphicsDevice.Clear(Color.White);
            graphicsDevice.SetRenderTarget(null);
        }
开发者ID:uhealin,项目名称:asskicker,代码行数:8,代码来源:LineRenderer.cs

示例10: LineRenderer

 public LineRenderer(GraphicsDevice p_gd, ContentManager p_content)
 {
     m_lineTexture = new RenderTarget2D(p_gd, 1, 1);
     p_gd.SetRenderTarget(m_lineTexture);
     p_gd.Clear(Color.White);
     p_gd.SetRenderTarget(null);
     m_aalineTexture = p_content.Load<Texture2D>("aaline");
 }
开发者ID:Hoodad,项目名称:Editor_TLCB,代码行数:8,代码来源:LineRenderer.cs

示例11: GetTexture

 //Sam was here
 //Do not use unless you plan on doing pixel perfect collision (I don't think we will but just in case)
 public Texture2D GetTexture(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch)
 {
     RenderTarget2D renderTarget = new RenderTarget2D(graphicsDevice, frameWidth, frameHeight);
     graphicsDevice.SetRenderTarget(renderTarget);
     graphicsDevice.Clear(new Color(0, 0, 0, 0));
     spriteBatch.Begin();
     Draw(spriteBatch, new Rectangle(0, 0, frameWidth, frameHeight));
     spriteBatch.End();
     graphicsDevice.SetRenderTarget(null);
     return renderTarget;
 }
开发者ID:TeamHiddenPenguin,项目名称:ButlerQuest,代码行数:13,代码来源:Animation.cs

示例12: Bar

        public Bar(Texture2D texture, Vector2 position,GraphicsDevice graphicsDevice)
            : base(texture, new Vector2(-100,-100), Microsoft.Xna.Framework.Color.White, 0.0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0.0f)
        {
            rt2d = new RenderTarget2D(graphicsDevice, texture.Width - 1, texture.Height - 1);
            graphicsDevice.SetRenderTarget(rt2d);
            graphicsDevice.Clear(Microsoft.Xna.Framework.Color.Red);
            graphicsDevice.SetRenderTarget(null);

            metervalue = 1;
            barmeter = new Microsoft.Xna.Framework.Rectangle((int)position.X, (int)position.Y, 0, (int)texture.Height - 2);
            width = texture.Width - 2;
        }
开发者ID:cikidot,项目名称:game-xna-herobot,代码行数:12,代码来源:Bar.cs

示例13: GenerateShadow

        public void GenerateShadow(Texture2D shadowmap, SpriteBatch spriteBatch,GraphicsDevice graphicsDevice,List<Effect>EffectList)
        {
            #region Snatch texture
            graphicsDevice.SetRenderTarget(area);
            spriteBatch.Begin(SpriteSortMode.Immediate,BlendState.Opaque);
            graphicsDevice.Clear(Color.White);
            spriteBatch.Draw(shadowmap,
                new Rectangle(0, 0, range * 2, range * 2),
                RenderArea,
                Color.White);
            #endregion
            #region Calculate Fade
            graphicsDevice.SetRenderTarget(output[1]);
            EffectList[1].CurrentTechnique.Passes[0].Apply();
            spriteBatch.Draw(area, new Rectangle(0, 0, range * 2, range * 2), Color.White);
            #endregion
            #region Calculate Distorted
            graphicsDevice.SetRenderTarget(output[0]);

            EffectList[0].CurrentTechnique.Passes[0].Apply();
            spriteBatch.Draw(output[1], new Rectangle(0, 0, range * 2, range * 2), Color.White);
            #endregion

            #region Horizontal Reduction
            int order = 0;
            //represents the order of the power of 2 used in the reduction
            //first pass of the lap makes the pixel the min of itself and the pixel near it (2^0)
            //second pass makes the pixel the min of itself and the one two pixels to the right
            // and so on until 2^order>range
            EffectList[2].Parameters["range"].SetValue(range);
            EffectList[2].CurrentTechnique.Passes[0].Apply();
            while (Math.Pow(2, order) <= range)
            {
                graphicsDevice.SetRenderTarget(output[(order + 1) ]);
                EffectList[2].Parameters["order"].SetValue((float)(Math.Pow(2, order)) / (range * 2));
                spriteBatch.Draw(output[order ], new Rectangle(0, 0, range * 2, range * 2), Color.White);
                EffectList[2].CurrentTechnique.Passes[0].Apply();
                order++;
            }
            #endregion
            #region Shadow Resolve
            graphicsDevice.SetRenderTarget(area);
            EffectList[3].CurrentTechnique.Passes[0].Apply();
            spriteBatch.Draw(output[order  ], new Rectangle(0, 0, range * 2, range * 2), Color.White);
            #endregion region Shadow Resolve
            spriteBatch.End();
            graphicsDevice.SetRenderTarget(null);
        }
开发者ID:Fireeyes,项目名称:The-Day-After,代码行数:48,代码来源:LightSource.cs

示例14: DrawReflectionMap

        public void DrawReflectionMap(GraphicsDevice device, GameTime gameTime)
        {
            UpdateReflectionViewMatrix(DisplayController.Camera);

            Vector4 reflectionPlane = CreatePlane(terrainWater.WaterHeight, new Vector3(0, -1, 0), true);

            device.SetRenderTarget(terrainWater.ReflectionRenderTarget);

            device.Clear(ClearOptions.Target, Color.Black, 1.0f, 0);
            terrainWater.Board.GetDrawer().Draw(device, gameTime, reflectionPlane);

            Matrix cameraMatrix = DisplayController.Camera.CameraMatrix;

            DisplayController.Camera.CameraMatrix = terrainWater.ReflectionViewMatrix;

            foreach (GameObject o in terrainWater.MissionController.GetMissionObjects())
            {
                o.GetDrawer().Draw(device, gameTime, reflectionPlane);
            }

            DisplayController.Camera.CameraMatrix = cameraMatrix;

            terrainWater.ReflectionMap = terrainWater.ReflectionRenderTarget;
            /*using (FileStream fileStream = File.OpenWrite("reflectionmap.jpg"))
            {
                terrainWater.ReflectionMap.SaveAsJpeg(fileStream, terrainWater.ReflectionMap.Width, terrainWater.ReflectionMap.Height);
                fileStream.Close();
            }*/
        }
开发者ID:smarthaert,项目名称:icgame,代码行数:29,代码来源:TerrainWaterDrawer.cs

示例15: ResolveRenderTarger

 public static void ResolveRenderTarger(GraphicsDevice device)
 {
     device.SetRenderTarget(null);
     miniMap = minimap;
     Camera.upDownRot = MathHelper.ToRadians(-45);
     Camera.cameraPosition = new Vector3(30, 80, 100);
 }
开发者ID:patrykos91,项目名称:Laikos,代码行数:7,代码来源:Minimap.cs


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