How to draw a plain red 2D rectangle with SharpDX?
- I have a SharpDX.Direct3D9.Device available from a library that sets up a Direct3D v9 device for me, so I'm hoping to be able to use that?
Found a tutorial on how to use Direct2D1 to draw a basic rectangle, but the code seems to be dependent on a Direct3D11 device, which I don't have - I need to be able to get the job done without Direct3D11 and without 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; }
Could draw a sprite using something like the following:
Loading a texture this way will create a square texture, if the device capabilities support it then you can specify the dimensions when you load the texture, e.g.
Otherwise you can scale the X and Y appropriately within the transform: