筆者はUnityなどでShaderを書いていることでC++やDirectXに関しての多少の知見はありますが、本格的に勉強をしたことがなかったので、今回はDirectX12のサンプルを試していきます。
今回はMicrosoft LearnのSampleCodeよりTriangles Sampleを試していきます。
〇環境
・VisualStudio2022
・Windows11PC
slnファイルをVisualStudioで開き実行を行うことでウィンドウが開きます。
〇Triangles Sample
このサンプルではDirectX12を使用したTriangles(三角形)を描画します。
つまり、最もシンプルなサンプルになります。
Main.cppは次のようになります。
#include "stdafx.h" #include "D3D12HelloTriangle.h" _Use_decl_annotations_ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) { D3D12HelloTriangle sample(1280, 720, L"D3D12 Hello Triangle"); return Win32Application::Run(&sample, hInstance, nCmdShow); }
それぞれ軽く見ていきます。
**WinMain**
はWindowsアプリのエントリーポイント
HINSTANCE hInstance
はアプリケーションのインスタンスハンドルを格納する
LPSTR
はコマンドラインの引数を受けとります。
nCmdShow
はウィンドウの表示方法を指定している。
D3D12HelloTriangle sample(1280, 720, L"D3D12 Hello Triangle");
はD3D12HelloTriangleのSampleメソッドを実行している。 引数はウィンドウの大きさ、そしてウィンドウのタイトル
例えば次のように処理を変えることでウィンドウのサイズが変わります。
D3D12HelloTriangle sample(1280*2, 720, L"D3D12 Hello Triangle");
Main.cppではD3D12HelloTrianglesのsampleメソッドをただ実行していることがわかりました。
最後の
return Win32Application::Run(&sample, hInstance, nCmdShow);
はWin32Application::Runを呼び出し、アプリケーションを実行しています。
実際の処理はsampleメソッド=D3D12HelloTrianglesの処理になります。
こちらの処理はまた次回見ていきます。