using System; using System.Drawing; using System.Windows.Forms; using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; public class HelloForm : Form { private Device device_; private PresentParameters presentParam_; private Microsoft.DirectX.Direct3D.Font font_; public HelloForm() { this.Size = new Size(640, 480); this.Text = "Hello, World!"; } public bool InitD3D() { presentParam_ = new PresentParameters(); presentParam_.Windowed = true; presentParam_.SwapEffect = SwapEffect.Discard; device_ = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, presentParam_); InitFont(); return true; } private void InitFont() { FontDescription fd = new FontDescription(); fd.Height = 16; fd.FaceName = "MS ゴシック"; font_ = new Microsoft.DirectX.Direct3D.Font(device_, fd); } public void Render() { if (device_ == null) { return; } device_.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0); device_.BeginScene(); font_.DrawText(null, "Hello, DirectX(C#) World!", 10, 10, Color.White); device_.EndScene(); device_.Present(); } [STAThread] public static void Main() { using (HelloForm form = new HelloForm()) { form.InitD3D(); form.Show(); while (form.Created) { form.Render(); Application.DoEvents(); } } } }