【发布时间】:2015-07-05 12:07:35
【问题描述】:
如何用 SharpDX 绘制一个纯红色的 2D 矩形?
- 我有一个 SharpDX.Direct3D9.Device available from a library 为我设置 Direct3D v9 设备,所以我希望能够使用它?
-
Found a tutorial on how to use Direct2D1 to draw a basic rectangle,但代码似乎依赖于我没有的 Direct3D11 设备 - 我需要能够在没有 Direct3D11 和 Direct3D10 的情况下完成工作
unsafe int PresentHook(IntPtr devicePtr, SharpDX.Rectangle* pSourceRect, SharpDX.Rectangle* pDestRect, IntPtr hDestWindowOverride, IntPtr pDirtyRegion) { _isUsingPresent = true; SharpDX.Direct3D9.Device device = (SharpDX.Direct3D9.Device)devicePtr; // How to draw rectangle here? if (pSourceRect == null || *pSourceRect == SharpDX.Rectangle.Empty) device.Present(); else { if (hDestWindowOverride != IntPtr.Zero) device.Present(*pSourceRect, *pDestRect, hDestWindowOverride); else device.Present(*pSourceRect, *pDestRect); } return SharpDX.Result.Ok.Code; }
【问题讨论】:
-
您不需要 Direct3D11 GPU 也能使用它。 Direct3D 有一个叫做 Feature Levels 的东西,这意味着它将运行 D3D11,但只有 GPU 可用的功能。因此,除非您运行的是 Windows XP,否则您将能够运行它。如果需要,请打开
Run...并输入dxdiag。然后寻找DirectX version。如果是 DirectX 11 或更高版本,那么您就可以开始了。 -
@LHLaurini 问题是我有一个 SharpDX.Direct3D9.Device 可供我从库中使用,我该如何使用它? (我没有 SharpDX.Direct3D11.Device)
-
对不起,我擅长将 DirectX 与本机代码一起使用。我不太喜欢管理方面。所以其他人将不得不回答你。您是否尝试运行该 DX11 代码?抱歉,说到 C#,我很笨。
标签: c# directx 2d directx-9 sharpdx