本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.RenderTarget2D.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTarget2D.SetData方法的具体用法?C# RenderTarget2D.SetData怎么用?C# RenderTarget2D.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Graphics.RenderTarget2D
的用法示例。
在下文中一共展示了RenderTarget2D.SetData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvertGradient
public static void InvertGradient(RenderTarget2D textureInput, ref RenderTarget2D textureOutput, float state,
Color c1, Color c2)
{
if (textureInput.Width != textureOutput.Width || textureInput.Height != textureOutput.Height)
throw new Exception("Textures must be the same size!");
Color[] c = new Color[textureInput.Width * textureInput.Height];
textureInput.GetData<Color>(c);
float cr = (float)(c1.R + c2.R) / 2 / 255;
float cg = (float)(c1.G + c2.G) / 2 / 255;
float cb = (float)(c1.B + c2.B) / 2 / 255;
float dr = (float)(c1.R - c2.R) / 255;
float dg = (float)(c1.G - c2.G) / 255;
float db = (float)(c1.B - c2.B) / 255;
float tr, tg, tb;
for (int i = 0; i < c.Length && c[i].A != 0; i++)
{
tr = (float)c[i].R / 255;
tg = (float)c[i].G / 255;
tb = (float)c[i].B / 255;
tr = tr - (tr - cr) * 2 * state;
tg = tg - (tg - cg) * 2 * state;
tb = tb - (tb - cb) * 2 * state;
c[i].R = (byte)(tr * 255);
c[i].G = (byte)(tg * 255);
c[i].B = (byte)(tb * 255);
}
textureOutput.SetData<Color>(c);
}
示例2: Dump
public void Dump() {
try {
Texture2D texture = Texture2D.FromStream(this.GraphicsDevice, File.OpenRead(@"C:\Users\Oxysoft\Desktop\_splitter_tool\input.png"));
string dumploc = @"C:\Users\Oxysoft\Desktop\_splitter_tool\newdump\";
const int cols = 10;
const int rows = 10;
TileableTexture tileableTexture = new TileableTexture(texture, cols, rows);
List<RenderTarget2D> results = new List<RenderTarget2D>();
Color chroma1 = new Color(0xBF, 0xC8, 0xFF);
Color chroma2 = new Color(0xD8, 0xDE, 0xFF);
for (int y = 0; y < rows; y++) {
for (int x = 0; x < cols; x++) {
int[] order = new int[4 * 4];
order[0] = 5;
order[1] = 11;
order[2] = 5;
order[3] = 8;
order[4] = 6;
order[5] = 3;
order[6] = 6;
order[7] = 9;
order[8] = 1;
order[9] = 4;
order[10] = 1;
order[11] = 7;
order[12] = 0;
order[13] = 2;
order[14] = 0;
order[15] = 10;
RenderTarget2D renderTarget = new RenderTarget2D(GraphicsDevice, 96, 128);
TileableTexture tileableRenderTarget = new TileableTexture(renderTarget, 3, 4);
GraphicsDevice.SetRenderTarget(renderTarget);
SpriteBatch spriteBatch = new SpriteBatch(GraphicsDevice);
spriteBatch.Begin();
spriteBatch.Draw(texture, new Rectangle(0, 0, 96, 128), tileableTexture.GetSource(tileableTexture.GetIndex(x, y)), Color.White);
spriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
RenderTarget2D resultTarget = new RenderTarget2D(GraphicsDevice, 128, 128);
TileableTexture tileableResultTarget = new TileableTexture(resultTarget, 4, 4);
GraphicsDevice.SetRenderTarget(resultTarget);
GraphicsDevice.Clear(Color.Transparent);
spriteBatch.Begin();
for (int i = 0; i < order.Length; i++) {
Rectangle target = tileableResultTarget.GetSource(i);
spriteBatch.Draw(renderTarget, target, tileableRenderTarget.GetSource(order[i]), Color.White);
}
spriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
//----> Start of CHROMA CLEARING
Color[] colors = new Color[resultTarget.Width * resultTarget.Height];
resultTarget.GetData<Color>(colors);
for (int i = 0; i < colors.Length; i++) {
if (colors[i] == chroma1 || colors[i] == chroma2) colors[i] = Color.Transparent;
}
resultTarget.SetData<Color>(colors);
//End of CHROMA CLEARING <----
results.Add(resultTarget);
}
}
for (int i = 0; i < results.Count; i++) {
results[i].SaveAsPng(File.OpenWrite(dumploc + i + ".png"), results[i].Width, results[i].Height);
}
} catch (Exception e) {
Console.WriteLine("what da fack");
}
}
示例3: XuatAnhKyTu
//.........这里部分代码省略.........
}
}
}
//thuc hien can le va can dong
bonenvunganh = new RenderTarget2D(thietbidohoa, rongkhung + bovien.X + bovien.Width, daikhung + bovien.Y + bovien.Height);
thietbidohoa.SetRenderTarget(bonenvunganh);
thietbidohoa.Clear(maunen);
nenve.Begin();
int dodaitoanbochu = demdong * (dodaikytu + dancachdong) - dancachdong;
int giasocandong = 0;
if (candong == 3) giasocandong = daikhung - dodaitoanbochu;
else if (candong == 2) giasocandong = (int)((daikhung - dodaitoanbochu) / 2);
vitrighepx = bovien.X; vitrighepy = giasocandong + bovien.Y;
if (canle == 3)
{
for (int i = 0; i < demdong; i++)
{
vitrighepx = rongkhung - mangdorongdong[i] + bovien.X;
vitrighepy = i * (dodaikytu + dancachdong) + giasocandong + bovien.Y;
for (int j = 0; j < demkytu[i]; j++)
{
if (matranvanban[j, i] == -1)
{
nenve.Draw(anhkytucham, new Vector2(vitrighepx, vitrighepy), Color.White);
vitrighepx += dorongkytucham + dancachchu;
}
else
{
if ((j == 0) & ((giatrikytu[matranvanban[j, i]] == " ") | (giatrikytu[matranvanban[j, i]] == "|"))) continue;
nenve.Draw(anhkytu[matranvanban[j, i]], new Vector2(vitrighepx, vitrighepy), Color.White);
vitrighepx += dorongkytu[matranvanban[j, i]] + dancachchu;
}
}
}
}
else if (canle == 2)
{
for (int i = 0; i < demdong; i++)
{
vitrighepx = (int)((rongkhung - mangdorongdong[i]) / 2) + bovien.X;
vitrighepy = i * (dodaikytu + dancachdong) + giasocandong + bovien.Y;
for (int j = 0; j < demkytu[i]; j++)
{
if (matranvanban[j, i] == -1)
{
nenve.Draw(anhkytucham, new Vector2(vitrighepx, vitrighepy), Color.White);
vitrighepx += dorongkytucham + dancachchu;
}
else
{
if ((j == 0) & ((giatrikytu[matranvanban[j, i]] == " ") | (giatrikytu[matranvanban[j, i]] == "|"))) continue;
nenve.Draw(anhkytu[matranvanban[j, i]], new Vector2(vitrighepx, vitrighepy), Color.White);
vitrighepx += dorongkytu[matranvanban[j, i]] + dancachchu;
}
}
}
}
else
{
for (int i = 0; i < demdong; i++)
{
vitrighepx = bovien.X;
vitrighepy = i * (dodaikytu + dancachdong) + giasocandong + bovien.Y;
for (int j = 0; j < demkytu[i]; j++)
{
if (matranvanban[j, i] == -1)
{
nenve.Draw(anhkytucham, new Vector2(vitrighepx, vitrighepy), Color.White);
vitrighepx += dorongkytucham + dancachchu;
}
else
{
if ((j == 0) & ((giatrikytu[matranvanban[j, i]] == " ") | (giatrikytu[matranvanban[j, i]] == "|"))) continue;
nenve.Draw(anhkytu[matranvanban[j, i]], new Vector2(vitrighepx, vitrighepy), Color.White);
vitrighepx += dorongkytu[matranvanban[j, i]] + dancachchu;
}
}
}
}
nenve.End();
thietbidohoa.SetRenderTarget(null);
if (mauchu != Color.White)
{
Color[] dulieumau = new Color[bonenvunganh.Width * bonenvunganh.Height];
bonenvunganh.GetData(dulieumau);
for (int x = 0; x < bonenvunganh.Width; x++)
{
for (int y = 0; y < bonenvunganh.Height; y++)
{
int vitri = x + y * bonenvunganh.Width;
if (dulieumau[vitri].R > 126)
{
dulieumau[vitri] = mauchu;
}
}
}
bonenvunganh.SetData(dulieumau);
}
return bonenvunganh;
}
示例4: Render
//TODO optimize
public void Render(RenderTarget2D fbo, RenderTarget2D bufferFBO, Renderer renderer, Texture2D distortionTexture = null)
{
if (fbo == null || bufferFBO == null || fbo.Width != W || fbo.Height != H || bufferFBO.Width != W || bufferFBO.Height != H)
return;
if (distortionTexture == null)
distortionTexture = MicroWorld.Graphics.Effects.Effects.liquidDistortionTexture;
bool b = renderer.IsDrawing;
bool s = renderer.IsScaeld;
var cfbo = renderer.CurFBO;
if (b)
renderer.End();
if (cfbo == bufferFBO)
renderer.DisableFBO();
renderer.GraphicsDevice.Textures[0] = null;
Color[] fboarr = new Color[W * H];
fixed(TileMapElement* ptrmap = tileMap)
fixed (Color* ptrfbo = fboarr)
{
for (int x = 0; x < W; x++)
{
for (int y = 0; y < H; y++)
{
*(ptrfbo + x + y * W) = (*(ptrmap + y + x * H)).level <= 1 ? Color.Transparent : Color.White;
}
}
}
bufferFBO.SetData<Color>(fboarr);
renderer.EnableFBO(fbo);
renderer.GraphicsDevice.Clear(Color.Transparent);
_setUpShader(distortionTexture);
renderer.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullNone,
MicroWorld.Graphics.Effects.Effects.liquid);
renderer.Draw(bufferFBO, new Vector2(), new Color(0, 108, 255));
renderer.End();
if (cfbo == fbo)
renderer.EnableFBO(bufferFBO);
if (b)
renderer.Begin(s);
}
示例5: createImage
public override global::System.Object createImage(global::org.xmlvm._nArrayAdapter<int> n1, int n2, int n3)
{
RenderTarget2D rt = new RenderTarget2D(SharedGraphicsDeviceManager.Current.GraphicsDevice, n2, n3);
int[] arr = n1.getCSharpArray();
rt.SetData(arr);
return new XNAImage(rt);
}
示例6: Create_Surfaces
/// <summary>
/// Creates the surfaces used by the effect
/// </summary>
private void Create_Surfaces()
{
//Initialize the positions and velocities of the point masses
Vector4[] initial_Positions = new Vector4[sizex * sizey];
Vector4[] initial_Velocities = new Vector4[sizex * sizey];
for (int i = 0; i < sizex * sizey; i++)
{
var x = i % sizex;
var y = i / sizey;
var coords = helper.Clip_Coords_of_point_UL(x, y);
initial_Positions[i] = new Vector4(coords.X, coords.Y, 0, 0);
}
for (int i = 0; i < sizex * sizey; i++)
{
initial_Velocities[i] = new Vector4(0, 0, 0, 1);// + new Vector2(0, 0));
}
var frame_buffer_format = device.PresentationParameters.BackBufferFormat;
//Something that has to do with gpu implementation details, it's explained in the comment lines below
var format_choice = SurfaceFormat.HdrBlendable;
//Most of the surfaces use the vector4 format, though it would probably also work using just vector2
//The gpu can't additively blend using IEEE floats
//so certain buffers that need to be written in additive blending for the effect to work,
//namely those gathering forces geometrically and per index,
//they instead use a surface suitable for hdr rendering that XNA provides
//which seems accurate enough, and supports additive blending
Initial_Position = new RenderTarget2D(device, sizex, sizey, false, SurfaceFormat.Vector4, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
Position0 = new RenderTarget2D(device, sizex, sizey, false, SurfaceFormat.Vector4, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
Position1 = new RenderTarget2D(device, sizex, sizey, false, SurfaceFormat.Vector4, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
Velocity0 = new RenderTarget2D(device, sizex, sizey, false, SurfaceFormat.Vector4, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
Velocity1 = new RenderTarget2D(device, sizex, sizey, false, SurfaceFormat.Vector4, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
Force_By_Index = new RenderTarget2D(device, sizex, sizey, false, SurfaceFormat.HdrBlendable, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
Force_By_Position_Accumulator = new RenderTarget2D(device, sizex, sizey, false, SurfaceFormat.HdrBlendable, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
Initial_Position.SetData(initial_Positions);
Position0.SetData(initial_Positions);
Position1.SetData(initial_Positions);
Velocity0.SetData(initial_Velocities);
Velocity1.SetData(initial_Velocities);
}
示例7: CloneRenderTarget
public static RenderTarget2D CloneRenderTarget(RenderTarget2D target)
{
var clone = new RenderTarget2D(target.GraphicsDevice, target.Width,
target.Height, target.LevelCount > 1, target.Format,
target.DepthStencilFormat, target.MultiSampleCount,
target.RenderTargetUsage);
for (int i = 0; i < target.LevelCount; i++)
{
double rawMipWidth = target.Width / Math.Pow(2, i);
double rawMipHeight = target.Height / Math.Pow(2, i);
// make sure that mipmap dimensions are always > 0.
int mipWidth = (rawMipWidth < 1) ? 1 : (int)rawMipWidth;
int mipHeight = (rawMipHeight < 1) ? 1 : (int)rawMipHeight;
var mipData = new Color[mipWidth * mipHeight];
target.GetData(i, null, mipData, 0, mipData.Length);
clone.SetData(i, null, mipData, 0, mipData.Length);
}
return clone;
}
示例8: depthFrameSetUp
void depthFrameSetUp(DepthImageFrame frame, DepthImagePixel[] depthPixels, Color[] depthArray, RenderTarget2D depthTarget)
{
depthFramyBusy = true;
using (frame)
{
if (frame != null)
{
//Console.WriteLine("Has frame");
frame.CopyDepthImagePixelDataTo(depthPixels);
for (int i = 0; i < depthPixels.Length; i++)
{
int b = (depthPixels[i].Depth >= frame.MinDepth && depthPixels[i].Depth <= frame.MaxDepth && depthPixels[i].IsKnownDepth) ? depthPixels[i].Depth : 0;
if (depthPixels[i].Depth >= frame.MaxDepth)
{
b = frame.MaxDepth;
}
float f = (float)((float)b - frame.MinDepth) / (float)(frame.MaxDepth - frame.MinDepth);
depthArray[i] = new Color(f, f, f, 1);
}
depthTarget.SetData(depthArray);
DepthImagePoint[] dip = new DepthImagePoint[kinect.ColorStream.FrameWidth * kinect.ColorStream.FrameHeight];
kinect.CoordinateMapper.MapColorFrameToDepthFrame(kinect.ColorStream.Format,
kinect.DepthStream.Format, depthPixels, dip);
for (int i = 0; i < depthCoordArray.Length; i++)
{
depthCoordArray[i] = new Color((float)dip[i].X / (float)kinect.ColorStream.FrameWidth, (float)dip[i].Y / (float)kinect.ColorStream.FrameHeight, 0, 1);
}
depthCoordMap.SetData(depthCoordArray);
}
else
{
}
}
depthFramyBusy = false;
}
示例9: colorFrameSetUp
void colorFrameSetUp(ColorImageFrame frame, byte[] colorArray, RenderTarget2D colorTarget)
{
colorFrameBusy = true;
using (frame)
{
if (frame != null)
{
frame.CopyPixelDataTo(colorArray);
if (frame.Format == ColorImageFormat.RgbResolution640x480Fps30)
{
for (int i = 0; i < colorArray.Length; i += 4)
{
if (i < colorArray.Length - 3)
{
byte b = colorArray[i];
byte g = colorArray[i + 1];
byte r = colorArray[i + 2];
byte a = colorArray[i + 3];
colorArray[i] = r;
colorArray[i + 1] = g;
colorArray[i + 2] = b;
colorArray[i + 3] = 255;
}
}
}
else if (frame.Format == ColorImageFormat.InfraredResolution640x480Fps30)
{
UInt16 int16 = 0;
for (int i = 0; i < colorArray.Length; i += 2)
{
if (i < colorArray.Length - 1)
{
byte b1 = colorArray[i], b2 = colorArray[i + 1];
int16 = (UInt16)(b2 << 8 | b1);
float f = (int16 / (float)ushort.MaxValue) * (16f);
byte b = (byte)f;
byte b12 = (byte)(b << 4 | b), b22 = (byte)(b << 4 | b);
colorArray[i] = b12;
colorArray[i + 1] = b22;
}
}
}
//kinect.CoordinateMapper.MapDepthFrameToColorFrame(
GraphicsDevice.Textures[0] = null;
colorTarget.SetData(colorArray);
}
}
colorFrameBusy = false;
}