开发环境:Visual Studio 2019
新建项目:.NET Framework 的控制台
需要nuget的包有:
- SharpDX
- SharpDX.D3DCompiler
- SharpDX.Desktop
- SharpDX.Direct2D1
- SharpDX.Direct3D11
- SharpDX.DXGI
完整代码:
using SharpDX.Windows;
using System;
using System.Drawing;
namespace CreateWindow
{
class Program
{
static void Main(string[] args)
{
using (var temp = new CreateSharpDXWindow())
{
temp.Run();
}
}
}
class CreateSharpDXWindow : IDisposable
{
private RenderForm _renderForm;
private const int Width = 1280;
private const int Height = 720;
public CreateSharpDXWindow()
{
_renderForm = new RenderForm();
_renderForm.ClientSize = new Size(Width, Height);
}
public void Run()
{
RenderLoop.Run(_renderForm, RenderCallback);
}
private void RenderCallback()
{
}
public void Dispose()
{
_renderForm?.Dispose();
}
}
}