當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。