BooでDirectX

ティーポットを表示するだけのサンプル。ウィンドウをリサイズするだけで表示がおかしくなります。(^^;

import System
import System.Drawing
import System.Windows.Forms
import Microsoft.DirectX
import Microsoft.DirectX.Direct3D

class MyForm (Form):
  device as Device = null
  mesh as Mesh = null

  def constructor ():
    ClientSize = System.Drawing.Size (400, 300)
    Text = "Boo Direct3D Sample"

  def Init () as bool:
    try:
      ps = PresentParameters (Windowed:true, SwapEffect:SwapEffect.Discard, 
          EnableAutoDepthStencil:true, AutoDepthStencilFormat:DepthFormat.D16) 
      device = Device (0, DeviceType.Hardware, self, CreateFlags.SoftwareVertexProcessing, (ps, ))
      device.RenderState.ZBufferEnable = true
      device.Material = Material (Diffuse:Color.White)
      device.Lights [0].Type = LightType.Directional
      device.Lights [0].Direction = Vector3 (1.0, -1.0, 1.0)
      device.Lights [0].Diffuse = Color.White
      device.Lights [0].Enabled = true
      device.Lights [0].Update ()
      device.RenderState.Lighting = true
      mesh = Mesh.Teapot (device)
    except:
      return false
    return true

  protected override def OnPaint (e as PaintEventArgs):
    return if device == null
    device.Clear (ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkBlue, 1.0, 0)
    device.BeginScene ()
    device.Transform.View = Matrix.LookAtLH (Vector3 (0.0, 2.0, -3.0), 
        Vector3 (0.0, 0.0, 0.0), Vector3 (0.0, 1.0, 0.0))
    p = device.PresentationParameters
    aspect = cast (single, p.BackBufferWidth) / cast (single, p.BackBufferHeight)
    device.Transform.Projection = Matrix.PerspectiveFovLH (cast (single, Math.PI / 4.0), aspect, 1.0, 100.0)
    mesh.DrawSubset (0)
    device.EndScene ()
    try:
      device.Present ()
    except:  
      pass

def Main ():
  form = MyForm ()
  if not form.Init ():
    return
  Application.Run (form)