Version 0.1.1
GfxControls is a lightweight C# library containing WPF and WinForms controls that enables embedding a DirectX, OpenGL, and Vulkan windows within an application.
Framework | DirectX | OpenGL | Vulkan |
---|---|---|---|
WPF | ✔ | ✖ | ✖ |
WinForms | ✔ | ✖ | ✖ |
API | Version | WPF | WinForms |
---|---|---|---|
DirectX | 9 | ✖ | ✖ |
10 | ✖ | ✖ | |
11 | ✔ | ✔ | |
12 | ✖ | ✖ | |
OpenGL | 3.3 | ✖ | ✖ |
4.6 | ✖ | ✖ | |
Vulkan | 1.0 | ✖ | ✖ |
1.1 | ✖ | ✖ |
-
Add a Reference
ReferenceGfxControls.WPF.dll
orGfxControls.Forms.dll
in your project. -
Add the Control in XAML
IncludeGfxControls.WPF/Forms.DirectX.D3D11Host
in your XAML file. -
Initialize DirectX
Wait forD3D11Host.IsDXInitialized
to be true or subscribe to theD3D11Host.DXInitialized
event before accessing DirectX resources. -
Access DirectX Interfaces
Use the provided DX interfaces directly in your native code or cast them to managed objects using libraries like SharpDX. You can access these through properties that return anIntPtr
.
Exposed Interfaces: The following DirectX interfaces are available:
IDXGIDevice
IDXGISwapChain
IDXGISwapChain1
ID3D11Device
ID3D11DeviceContext
Example: Convert Interface Pointers to SharpDX Objects:
You can cast the exposed interfaces to SharpDX objects using ComObject.FromPointer
:
//D3D11Host dxHost;
SharpDX.DXGI.Device dxdevice = ComObject.FromPointer<SharpDX.DXGI.Device>(dxHost.DXGIDevice);
SharpDX.DXGI.SwapChain swapChain = ComObject.FromPointer<SharpDX.DXGI.SwapChain>(dxHost.SwapChain);
SharpDX.DXGI.SwapChain1 swapChain1 = ComObject.FromPointer<SharpDX.DXGI.SwapChain1>(dxHost.SwapChain1);
SharpDX.Direct3D11.Device device = ComObject.FromPointer<SharpDX.Direct3D11.Device>(dxHost.D3DDevice);
SharpDX.Direct3D11.DeviceContext context = ComObject.FromPointer<SharpDX.Direct3D11.DeviceContext>(dxHost.DeviceContext);
Explore These Example Projects:
- WPF SharpDX Example
- WinForms SharpDX Example
- WPF CLI Example (Coming Soon)
Coming Soon
Coming Soon
-
Select Configuration
- Choose the build configuration you need, such as
Debug
,Release
, or any custom configurations. - The project includes multiple configurations for different .NET frameworks, including .NET 8, .NET 6, .NET Core 3.1, and .NET Framework 4.7.
- Choose the build configuration you need, such as
-
Restore NuGet Packages (Optional)
- Open the
Package Manager Console
in Visual Studio and run:dotnet restore
- Restore the CLI project using Visual Studio Command Prompt:
msbuild GfxControls.CLI\GfxControls.CLI.vcxproj /t:Restore
- Open the
-
Build
- Compile the WpfGfxControls or an example project in Visual Studio.
Warning: This is now handled using OnConfigChange.targets, be aware if importing GfxControls.CLI.vcxproj to another solution, as files/folders are deleted relative to $(SolutionDir)
.
If the GfxControls.CLI does not build after changing configurations or frameworks, try the following steps:
- Clean the Project in Visual Studio (
GfxControls.CLI
>Clean
). - Restore NuGet Packages using MSBuild.
- Reload the Project in Visual Studio to ensure settings are updated.
- Delete Intermediate and Output Directories like
bin
,obj
andFramework
if any build issues persist.