Hello, DirectX(VB.NET) World!
Posted on 7月 29th, 2012 by cx20
Win32 DirectX(VB.NET)
DirectX はマイクロソフトが Wnidows 用に開発したマルチメディア処理用 API である。
.NET Framework 用の DirectX ライブラリとしては、DirectX SDK より入手可能な Managed DirectX がある。
以下は VB.NET における Managed DirectX アプリケーション の例となっている。
ソースコード
Imports System Imports System.Drawing Imports System.Windows.Forms Imports Microsoft.DirectX Imports Microsoft.DirectX.Direct3D Public Class HelloForm Inherits Form Private device_ As Device Private presentParam_ As PresentParameters Private font_ As Microsoft.DirectX.Direct3D.Font Public Sub New() MyBase.Size = New Size(640, 480) Me.Text = "Hello, World!" End Sub Public Function InitD3D() As Boolean Me.presentParam_ = New PresentParameters() Me.presentParam_.Windowed = True Me.presentParam_.SwapEffect = SwapEffect.Discard Me.device_ = New Device(0, DeviceType.Hardware, Me, CreateFlags.HardwareVertexProcessing, Me.presentParam_) Me.InitFont() Return True End Function Private Sub InitFont() Dim description As FontDescription = New FontDescription() description.Height = 16 description.FaceName = "MS ゴシック" Me.font_ = New Microsoft.DirectX.Direct3D.Font(Me.device_, description) End Sub Public Sub Render() If Not Me.device_ Is Nothing Then Me.device_.Clear(ClearFlags.Target, Color.Blue, 1.0F, 0) Me.device_.BeginScene() Me.font_.DrawText(Nothing, "Hello, DirectX(VB.NET) World!", New Point(10, 10), Color.White) Me.device_.EndScene() Me.device_.Present() End If End Sub Shared Sub Main() Using helloForm As New HelloForm() helloForm.InitD3D() helloForm.Show() While helloForm.Created helloForm.Render() Application.DoEvents() End While End Using End Sub End Class |
コンパイル方法
C:¥> vbc ^ /target:winexe ^ /platform:x86 ^ /r:"C:WindowsMicrosoft.NETDirectX for Managed Code1.0.2902.0Microsoft.DirectX.dll" ^ /r:"C:WindowsMicrosoft.NETDirectX for Managed Code1.0.2902.0Microsoft.DirectX.Direct3D.dll" ^ /r:"C:WindowsMicrosoft.NETDirectX for Managed Code1.0.2911.0Microsoft.DirectX.Direct3DX.dll" ^ Hello.vb |
実行結果
+------------------------------------------+ |Hello, World! [_][~][X]| +------------------------------------------+ |Hello, DirectX(VB.NET) World! | | | | | | | | | | | | | | | | | | | +------------------------------------------+ |
Tags: DirectX