本文整理汇总了C#中SharpDX.Direct2D1.RenderTarget.BeginDraw方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTarget.BeginDraw方法的具体用法?C# RenderTarget.BeginDraw怎么用?C# RenderTarget.BeginDraw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpDX.Direct2D1.RenderTarget
的用法示例。
在下文中一共展示了RenderTarget.BeginDraw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: beginDraw
public IDisposable beginDraw(out IDrawingContext context)
{
var surface = _texture.AsSurface();
var rtProperties = new RenderTargetProperties()
{
DpiX = 96,
DpiY = 96,
Type = RenderTargetType.Default,
PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
};
var renderTarget = new RenderTarget(_factory, surface, rtProperties);
var c = new RenderTargetDrawingContext(renderTarget, _width, _height);
context = c;
renderTarget.BeginDraw();
return new DisposeAction(() =>
{
renderTarget.EndDraw();
c.Dispose();
renderTarget.Dispose();
surface.Dispose();
});
}
示例2: Render
public static void Render(RenderTarget pRender, float pPercent)
{
if (Loading) return;
pRender.BeginDraw();
currentLevel.Render(pRender, pPercent);
pRender.EndDraw();
}
示例3: DrawingContext
/// <summary>
/// Initializes a new instance of the <see cref="DrawingContext"/> class.
/// </summary>
/// <param name="renderTarget">The render target to draw to.</param>
/// <param name="directWriteFactory">The DirectWrite factory.</param>
public DrawingContext(
RenderTarget renderTarget,
SharpDX.DirectWrite.Factory directWriteFactory)
{
_renderTarget = renderTarget;
_directWriteFactory = directWriteFactory;
_renderTarget.BeginDraw();
}
示例4: Main
static void Main()
{
var form = new RenderForm("KinectLight");
form.Size = new System.Drawing.Size(1920,1200);
var desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
SharpDX.Direct3D10.Device1 device;
SwapChain swapChain;
SharpDX.Direct3D10.Device1.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, desc, SharpDX.Direct3D10.FeatureLevel.Level_10_1, out device, out swapChain);
var d2dFactory = new SharpDX.Direct2D1.Factory();
var surface = Surface.FromSwapChain(swapChain, 0);
RenderTarget dc = new RenderTarget(d2dFactory, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
MainGame.Instance.Height = form.ClientSize.Height;
MainGame.Instance.Width = form.ClientSize.Width;
GameTime gameTime = new GameTime();
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute(
"API Default", "api/{controller}/{action}/{name}",
new { id = RouteParameter.Optional });
HttpSelfHostServer server = new HttpSelfHostServer(config);
server.OpenAsync().Wait();
RenderLoop.Run(form, () =>
{
gameTime.StartFrame();
MainGame.Instance.Update(gameTime);
dc.BeginDraw();
dc.Clear(Colors.White);
MainGame.Instance.Render(dc);
var res = dc.EndDraw();
swapChain.Present(1, PresentFlags.None);
//Thread.Sleep(1);
});
server.Dispose();
MainGame.Instance.Dispose();
dc.Dispose();
surface.Dispose();
d2dFactory.Dispose();
device.Dispose();
swapChain.Dispose();
}
示例5: Create3dObjects
public void Create3dObjects()
{
//Create RenderWindow
RenderWindowInstance = new ModelRenderWindow();
FormInstance = RenderWindowInstance.CreateWindow(1080,1240,FormStartPosition.CenterScreen);
//Create SwapChain
SwapChainCreator = new ModelSwapChainDesc();
SwapChainD = SwapChainCreator.CreateSwapChain(2, Usage.RenderTargetOutput, FormInstance.Handle, true, 0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm, 1,0,SwapChainFlags.AllowModeSwitch, SwapEffect.Discard);
//Create Device
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, SwapChainD, out GraphicsDevice, out NewSwapChain);
//Create Back buffer
BackBuffer = Surface.FromSwapChain(NewSwapChain, 0);
//Create Factory
FactoryD2D FactoryInstance = new FactoryD2D();
//Create RenderTarget
RenderTargetInstance = new ModelRenderTarget();
RenderTarget = RenderTargetInstance.CreateRenderTarget(SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT, new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Ignore), RenderTargetType.Default, RenderTargetUsage.None, BackBuffer, FactoryInstance);
RenderLoop.Run(FormInstance, () =>
{
RenderTarget.BeginDraw();
RenderTarget.Transform = Matrix3x2.Identity;
RenderTarget.Clear(Color.White);
using (var brush = new SolidColorBrush(RenderTarget, Color.Red))
{
//for (int x = 0; x < RenderTarget.Size.Width; x += 10)
// RenderTarget.DrawLine(new Vector2(x, 0), new Vector2(x, RenderTarget.Size.Height), brush, 0.5f);
//for (int y = 0; y < RenderTarget.Size.Height; y += 10)
// RenderTarget.DrawLine(new Vector2(0, y), new Vector2(RenderTarget.Size.Width, y), brush, 0.5f);
RenderTarget.DrawLine(new Vector2(300, 10), new Vector2(300, 300), brush,1.5f);
// RenderTarget.FillRectangle(new RectangleF(RenderTarget.Size.Width / 2 - 50, RenderTarget.Size.Height / 2 - 50, 100, 100), brush);
}
// RenderTarget.DrawRectangle(
// new RectangleF(RenderTarget.Size.Width / 2 - 100, RenderTarget.Size.Height / 2 - 100, 200, 200),
// new SolidColorBrush(RenderTarget, Color.CornflowerBlue));
RenderTarget.EndDraw();
NewSwapChain.Present(0, PresentFlags.None);
});
RenderTarget.Dispose();
NewSwapChain.Dispose();
GraphicsDevice.Dispose();
}
示例6: Begin
public void Begin(Canvas.ResolvedContext target)
{
Contract.Requires(target != null);
Contract.Assert(_Target == null);
Surface2D surface = target.Surface2D as Surface2D;
if (surface != null)
{
_Target = surface.Target2D;
_TargetRegion = target.Region;
_Target.BeginDraw();
return;
}
throw new InvalidOperationException();
}
示例7: Create
public D2D1.RenderTarget Create(D2D1.Factory factory, GDI.Graphics g, Map map)
{
//Monitor.Enter(_syncRoot);
// Dispose the _renderTexture if it is instantiated and not of the required size
CheckTexture(ref _renderTexture, map.Size);
// Create a new render texture if one is needed
if (_renderTexture == null)
{
_renderTexture = CreateRenderTargetTexture(_d3d11Device, map.Size.Width, map.Size.Height);
}
// Get the surface
var surface = _renderTexture.QueryInterface<DXGI.Surface>();
var res = new D2D1.RenderTarget(factory, surface, new D2D1.RenderTargetProperties(
D2D1.RenderTargetType.Hardware, new D2D1.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D1.AlphaMode.Premultiplied),
g.DpiX, g.DpiY, D2D1.RenderTargetUsage.None, D2D1.FeatureLevel.Level_DEFAULT));
res.BeginDraw();
return res;
}
示例8: OnEditViewportDrawPrimitives
private void OnEditViewportDrawPrimitives(Device device, RenderTarget target2D, Rectangle cliprectangle)
{
UiEncodingWindowSource source = _currentSource;
WflContent info = source?.Info;
if (info?.Header.TableType != WflHeader.LargeTable)
return;
int viewportX = _editViewport.X;
int viewportY = _editViewport.Y;
RectangleF rectangle = new RectangleF {Height = info.Header.LineHeight};
target2D.BeginDraw();
for (int i = 0; i < 256 * 2; i++)
{
if (i % 256 < 0x20)
continue;
int x, y;
info.GetOffsets(i, out x, out y);
x -= viewportX;
y -= viewportY;
byte before, width, after;
info.GetSizes(i, out before, out width, out after);
rectangle.X = x;
rectangle.Y = y;
rectangle.Width = width & 0x7F;
if (_charactersControl.CurrentMainIndices.Contains(i))
{
target2D.FillRectangle(rectangle, _selectedColorBrush);
if (before > 0x7F)
{
rectangle.Width = (0xFF - before) + 1;
rectangle.X = x;
}
else
{
rectangle.Width = before;
rectangle.X = x - before;
}
target2D.FillRectangle(rectangle, _spacingColorBrush);
if (after > 0x7F)
{
rectangle.Width = (0xFF - after) + 1;
rectangle.X = x + (width & 0x7F) - rectangle.Width;
}
else
{
rectangle.Width = after;
rectangle.X = x + width & 0x7F;
}
target2D.FillRectangle(rectangle, _spacingColorBrush);
}
else if (source.Chars[i % 256] == 0x00)
{
target2D.FillRectangle(rectangle, _notMappedColorBrush);
}
else
{
target2D.DrawRectangle(rectangle, _gridColorBrush, 1.0f);
}
}
int squareSize = info.Header.LineSpacing + info.Header.SquareDiff;
rectangle.Height = squareSize;
rectangle.Width = squareSize;
for (int i = 0; i < info.AdditionalTable.Length; i++)
{
int value = info.AdditionalTable[i];
if (value == 0)
continue;
rectangle.Y = (value >> 8) * squareSize - viewportY;
rectangle.X = (value & 0xFF) * squareSize - viewportX;
if (_charactersControl.CurrentAdditionalIndices.Contains(i))
target2D.FillRectangle(rectangle, _selectedColorBrush);
else if (source.Chars[i + 256] == 0x00)
target2D.FillRectangle(rectangle, _notMappedColorBrush);
else
target2D.DrawRectangle(rectangle, _gridColorBrush, 1.0f);
}
target2D.EndDraw();
}
示例9: Initialize
protected void Initialize(D2D1.RenderTarget renderTarget)
{
this.renderTarget = renderTarget;
renderTarget.BeginDraw ();
}
示例10: Main
private static void Main()
{
var form = new RenderForm("SharpDX - MiniTri Direct2D - Direct3D 10 Sample");
// SwapChain description
var desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription =
new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
// Create Device and SwapChain
Device1 device;
SwapChain swapChain;
Device1.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, desc, FeatureLevel.Level_10_0, out device, out swapChain);
var d2dFactory = new SharpDX.Direct2D1.Factory();
int width = form.ClientSize.Width;
int height = form.ClientSize.Height;
var rectangleGeometry = new RoundedRectangleGeometry(d2dFactory, new RoundedRectangle() { RadiusX = 32, RadiusY = 32, Rect = new RectangleF(128, 128, width - 128 * 2, height-128 * 2) });
// Ignore all windows events
Factory factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
// New RenderTargetView from the backbuffer
Texture2D backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
var renderView = new RenderTargetView(device, backBuffer);
Surface surface = backBuffer.QueryInterface<Surface>();
var d2dRenderTarget = new RenderTarget(d2dFactory, surface,
new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
var solidColorBrush = new SolidColorBrush(d2dRenderTarget, Color.White);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// Main loop
RenderLoop.Run(form, () =>
{
d2dRenderTarget.BeginDraw();
d2dRenderTarget.Clear(Color.Black);
solidColorBrush.Color = new Color4(1, 1, 1, (float)Math.Abs(Math.Cos(stopwatch.ElapsedMilliseconds * .001)));
d2dRenderTarget.FillGeometry(rectangleGeometry, solidColorBrush, null);
d2dRenderTarget.EndDraw();
swapChain.Present(0, PresentFlags.None);
});
// Release all resources
renderView.Dispose();
backBuffer.Dispose();
device.ClearState();
device.Flush();
device.Dispose();
device.Dispose();
swapChain.Dispose();
factory.Dispose();
}
示例11: Main
static void Main()
{
var form = new RenderForm("FUN STUFF PHYSXS");
// SwapChain description
var desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription =
new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
// Create Device and SwapChain
Device device;
SwapChain swapChain;
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, new SharpDX.Direct3D.FeatureLevel[] { SharpDX.Direct3D.FeatureLevel.Level_10_0 }, desc, out device, out swapChain);
var d2dFactory = new SharpDX.Direct2D1.Factory();
// Ignore all windows events
Factory factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
// New RenderTargetView from the backbuffer
Texture2D backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
var renderView = new RenderTargetView(device, backBuffer);
Surface surface = backBuffer.QueryInterface<Surface>();
var d2dRenderTarget = new RenderTarget(d2dFactory, surface,
new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
var solidColorBrush = new SolidColorBrush(d2dRenderTarget, Color.White);
var sim = new Simulation();
// Main loop
RenderLoop.Run(form, () =>
{
d2dRenderTarget.BeginDraw();
int width = form.ClientSize.Width;
int height = form.ClientSize.Height;
var simScaleX = sim.SimBounds.MaxX - sim.SimBounds.MinX;
var simScaleY = sim.SimBounds.MaxY - sim.SimBounds.MinY;
var viewScaleX = sim.ViewBounds.MaxX - sim.ViewBounds.MinX;
var viewScaleY = sim.ViewBounds.MaxY - sim.ViewBounds.MinY;
d2dRenderTarget.Clear(Color.Black);
foreach (Body body in sim.State)
{
var x = Convert.ToSingle((body.Pos.X - sim.SimBounds.MinX) * width / simScaleX);
var y = Convert.ToSingle((body.Pos.Y - sim.SimBounds.MinY) * height / simScaleY);
var xRad = Convert.ToSingle((body.Radius) * width / viewScaleX);
var yRad = Convert.ToSingle((body.Radius) * height / viewScaleY);
var elipse = new EllipseGeometry(d2dFactory, new Ellipse(new Vector2(x, y), xRad, yRad));
d2dRenderTarget.FillGeometry(elipse, solidColorBrush, null);
}
d2dRenderTarget.EndDraw();
sim.Step();
swapChain.Present(0, PresentFlags.None);
});
// Release all resources
renderView.Dispose();
backBuffer.Dispose();
device.ImmediateContext.ClearState();
device.ImmediateContext.Flush();
device.Dispose();
device.Dispose();
swapChain.Dispose();
factory.Dispose();
}
示例12: Run
//.........这里部分代码省略.........
// ---------------------------------------------------------------------------------------------------
// Acquire the mutexes. These are needed to assure the device in use has exclusive access to the surface
// ---------------------------------------------------------------------------------------------------
var device10Mutex = textureD3D10.QueryInterface<KeyedMutex>();
var device11Mutex = textureD3D11.QueryInterface<KeyedMutex>();
// ---------------------------------------------------------------------------------------------------
// Main rendering loop
// ---------------------------------------------------------------------------------------------------
bool first = true;
RenderLoop
.Run(form,
() =>
{
if(first)
{
form.Activate();
first = false;
}
// clear the render target to black
context.ClearRenderTargetView(renderTargetView, Colors.DarkSlateGray);
// Draw the triangle
context.InputAssembler.InputLayout = layoutColor;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBufferColor, VertexPositionColor.SizeInBytes, 0));
context.OutputMerger.BlendState = null;
var currentTechnique = effect.GetTechniqueByName("Color");
for (var pass = 0; pass < currentTechnique.Description.PassCount; ++pass)
{
using (var effectPass = currentTechnique.GetPassByIndex(pass))
{
System.Diagnostics.Debug.Assert(effectPass.IsValid, "Invalid EffectPass");
effectPass.Apply(context);
}
context.Draw(3, 0);
};
// Draw Ellipse on the shared Texture2D
device10Mutex.Acquire(0, 100);
renderTarget2D.BeginDraw();
renderTarget2D.Clear(Colors.Black);
renderTarget2D.DrawGeometry(tesselatedGeometry, solidColorBrush);
renderTarget2D.DrawEllipse(new Ellipse(center, 200, 200), solidColorBrush, 20, null);
renderTarget2D.EndDraw();
device10Mutex.Release(0);
// Draw the shared texture2D onto the screen, blending the 2d content in
device11Mutex.Acquire(0, 100);
var srv = new ShaderResourceView(device11, textureD3D11);
effect.GetVariableByName("g_Overlay").AsShaderResource().SetResource(srv);
context.InputAssembler.InputLayout = layoutOverlay;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBufferOverlay, VertexPositionTexture.SizeInBytes, 0));
context.OutputMerger.BlendState = blendStateTransparent;
currentTechnique = effect.GetTechniqueByName("Overlay");
for (var pass = 0; pass < currentTechnique.Description.PassCount; ++pass)
{
using (var effectPass = currentTechnique.GetPassByIndex(pass))
{
System.Diagnostics.Debug.Assert(effectPass.IsValid, "Invalid EffectPass");
effectPass.Apply(context);
}
context.Draw(4, 0);
}
srv.Dispose();
device11Mutex.Release(0);
swapChain.Present(0, PresentFlags.None);
});
// dispose everything
vertexBufferColor.Dispose();
vertexBufferOverlay.Dispose();
layoutColor.Dispose();
layoutOverlay.Dispose();
effect.Dispose();
shaderByteCode.Dispose();
renderTarget2D.Dispose();
swapChain.Dispose();
device11.Dispose();
device10.Dispose();
textureD3D10.Dispose();
textureD3D11.Dispose();
factory1.Dispose();
adapter1.Dispose();
sharedResource.Dispose();
factory2D.Dispose();
surface.Dispose();
solidColorBrush.Dispose();
blendStateTransparent.Dispose();
device10Mutex.Dispose();
device11Mutex.Dispose();
}
示例13: Render
public void Render(RenderTarget renderTarget)
{
if (!_enabled)
return;
renderTarget.BeginDraw();
renderTarget.Transform = Matrix3x2.Identity;
_outputView.Draw(renderTarget);
_inputView.Draw(renderTarget);
renderTarget.EndDraw();
}
示例14: Render
/// <summary>
/// Not implemented in interface to more directly manage draw order
/// plus it makes it's own begin/end draw calls
/// </summary>
/// <param name="renderTarget">The Direct2d render target</param>
public void Render(RenderTarget renderTarget)
{
if (_controlLayers.Count == 0) return;
renderTarget.BeginDraw();
// Draws in reverse
for (var node = _controlLayers.Last; node != null; node = node.Previous)
node.Value.Render(renderTarget);
renderTarget.EndDraw();
}
示例15: BeginDraw
public IDrawingTarget BeginDraw(Color? clearColor)
{
#if NETFX_CORE
var surface = _texture.QueryInterface<Surface>();
#else
var surface = _texture.AsSurface();
#endif
var rtProperties = new RenderTargetProperties
{
DpiX = 96,
DpiY = 96,
Type = RenderTargetType.Default,
PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
};
var renderTarget = new RenderTarget(_factory, surface, rtProperties);
renderTarget.BeginDraw();
// required to clear the render target
// not required on all machines, seems to be a driver decision.
renderTarget.Clear(clearColor != null ? clearColor.Value.import() : (Color4?)null);
var state = new DrawingState();
var transform = new DrawingTransform();
var drawingTarget = new DrawingTarget(state, transform, renderTarget, _width, _height);
var target = new DrawingTargetSplitter(
_backend,
state,
transform,
drawingTarget,
drawingTarget,
drawingTarget,
drawingTarget,
drawingTarget,
() =>
{
drawingTarget.Dispose();
renderTarget.EndDraw();
renderTarget.Dispose();
surface.Dispose();
});
var pixelAligner = PixelAligningDrawingTarget.Create(target, target.Dispose, state, transform);
return pixelAligner;
}