Created
November 14, 2018 02:33
-
-
Save baobao/afa2704aeb86f97afea5d72b55182ab2 to your computer and use it in GitHub Desktop.
背景クリアショートコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Windows.Forms; | |
using SlimDX.DXGI; | |
using SlimDX.Windows; | |
using SlimDX.Direct3D11; | |
using Device = SlimDX.Direct3D11.Device; | |
public class Test:Form | |
{ | |
RenderForm form; | |
Device device; | |
SwapChain swapChain; | |
RenderTargetView renderTarget; | |
public void Run() | |
{ | |
Test.CreateDeviceWithSwapChain(this, out device, out swapChain); | |
using (var backBuffer = SlimDX.Direct3D11.Resource.FromSwapChain<Texture2D>(swapChain, 0)) | |
{ | |
renderTarget = new RenderTargetView(device, backBuffer); | |
} | |
MessagePump.Run(this, Draw); | |
} | |
void Draw() | |
{ | |
device.ImmediateContext.ClearRenderTargetView( | |
renderTarget, | |
new SlimDX.Color4(1, 1, 0, 0) | |
); | |
// クリアの反映 | |
swapChain.Present(0, PresentFlags.None); | |
} | |
/// <summary> | |
/// デバイスとSwapChainを作成 | |
/// </summary> | |
static public SlimDX.Result CreateDeviceWithSwapChain( | |
Form form, | |
out SlimDX.Direct3D11.Device device, | |
out SwapChain swapChain | |
) | |
{ | |
return Device.CreateWithSwapChain( | |
// Direct3Dの機能を持つデバイス(GPU)を使用する | |
DriverType.Hardware, | |
// デバイスに特別なふるまいをさせるときは設定するが、基本はNone | |
DeviceCreationFlags.None, | |
// SwapChainの詳細設定 | |
new SwapChainDescription() | |
{ | |
// 2:ダブルバッファでティアリングを回避 | |
BufferCount = 2, | |
// 表示するウィンドウ | |
OutputHandle = form.Handle, | |
// falseにするとフルスクリーン | |
IsWindowed = true, | |
// SwapChainのマルチサンプル方法設定 | |
SampleDescription = new SampleDescription() | |
{ | |
Count = 1, | |
Quality = 0 | |
}, | |
// ウィンドウの大きさやリフレッシュレートに関する設定 | |
ModeDescription = new ModeDescription() | |
{ | |
// ウィンドウの幅 | |
Width = form.ClientSize.Width, | |
// ウィンドウの高さ | |
Height = form.ClientSize.Height, | |
// リフレッシュレート60Hz | |
RefreshRate = new SlimDX.Rational(60, 1), | |
// ウィンドウのフォーマット | |
// https://msdn.microsoft.com/ja-jp/library/ee416140(v=vs.85).aspx | |
Format = Format.R8G8B8A8_UNorm | |
}, | |
// 描画対象の使用方法 | |
// ウィンドウにただ表示するだけなので、RenderTargetOutputをセット | |
Usage = Usage.RenderTargetOutput | |
}, | |
out device, | |
out swapChain | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class Program | |
{ | |
/// <summary> | |
/// アプリケーションのメイン エントリ ポイントです。 | |
/// </summary> | |
static void Main() | |
{ | |
using (var test = new Test()) | |
{ | |
test.Run(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment