本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
// }
//}
}
示例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;
}
}
}
示例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);
}
示例9: LineRenderer
public LineRenderer(GraphicsDevice graphicsDevice)
{
lineTexture = new RenderTarget2D(graphicsDevice, 2, 3);
graphicsDevice.SetRenderTarget(lineTexture);
graphicsDevice.Clear(Color.White);
graphicsDevice.SetRenderTarget(null);
}
示例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");
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}*/
}
示例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);
}