開発環境 Microsoft Visual C++ 2010 Express (SP1)
実行環境 Microsoft Windows XP Home Edition (SP3)
プロジェクトの種類 空の CLR プロジェクト
プロジェクト名 MdxHello


MdxHello.cpp
/*
プロジェクト参照の追加
C:\WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2902.0
Microsoft.DirectX.dll
Microsoft.DirectX.Direct3D.dll
Microsoft.DirectX.Direct3DX.dll
*/
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
 
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace Microsoft::DirectX;
using namespace Microsoft::DirectX::Direct3D;
 
public ref class HelloForm : public Form
{
private:
	Device^ device;
	PresentParameters^ presentParam;
	Direct3D::Font^ font;	// Direct3DX参照
 
public:
	HelloForm()
	{
		Size = Drawing::Size(640,480);
		Text = "hello, world";
	}
 
	bool InitD3D()
	{
		presentParam = gcnew PresentParameters();
		presentParam->Windowed = true;
		presentParam->SwapEffect = SwapEffect::Discard;
		device = gcnew Device(0, DeviceType::Hardware, this,
			CreateFlags::HardwareVertexProcessing, presentParam);
		InitFont();
		return true;
	}
 
	void InitFont()
	{
		FontDescription fd;
		fd.Height = 16;
		fd.FaceName = "MS ゴシック";
		font = gcnew Direct3D::Font(device, fd);
	}
 
	void Render()
	{
		if (device == nullptr) return;
 
		device->Clear(ClearFlags::Target, Color::Blue, 1.0f, 0);
		device->BeginScene();
 
		font->DrawText(nullptr, "Hello, DirectX(C++/CLI) World!",
			10, 10, Color::White);
 
		device->EndScene();
		device->Present();
	}
};
 
int main(array<System::String ^> ^args)
{
	HelloForm^ form = gcnew HelloForm();
	form->InitD3D();
	form->Show();
	while (form->Created) {
		form->Render();
		Application::DoEvents();
	}
	return 0;
}
 
最終更新:2012年09月18日 12:58