-
VB.NET D3D基础例子CREATEDEVICE
'2006-3-18日 VB.NET DirectX和图形学学习
'
'
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Private m_dev As Device'Direct3D设备,即你的显卡
Sub New()
Me.ClientSize = New System.Drawing.Size(400, 300)
Me.Text = "Direct3D VB.NET"
End Sub
Public Sub Render()
If m_dev Is Nothing Then Exit Sub
m_dev.Clear(ClearFlags.ZBuffer Or ClearFlags.Target, Color.Red, 0.0, 0)
m_dev.BeginScene()
m_dev.EndScene()
m_dev.Present()
End Sub
Shared a As Integer
Public Shared Sub Main(ByVal CmdArgs() As String)
Dim frm1 As New Form1()
frm1.Show()
While frm1.Created
frm1.Render()
Application.DoEvents()
End While
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Me.Dispose()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim pp As New PresentParameters
pp.Windowed = True
pp.SwapEffect = SwapEffect.Discard
pp.EnableAutoDepthStencil = True
pp.AutoDepthStencilFormat = DepthFormat.D16
Me.m_dev = New Device(Nothing, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, pp)
If m_dev Is Nothing Then
MessageBox.Show("初始化设备失败")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
程序的流程从主函数开始,Direct3D通过控制D3D设备来控制屏幕图像的绘制。PresentParameter来配置设备的参数。