В инете нарыл учебник по DirectX под VB.NET,там есть такой код:
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class Form1
Private Devise As Device = Nothing
Private VertexBuffer As VertexBuffer = Nothing
Public Function InitializateGrapfics() As Boolean
Try
Dim PresentParameters As New PresentParameters
PresentParameters.Windowed = True
PresentParameters.SwapEffect = SwapEffect.Discard
Devise = New Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, PresentParameters)
AddHandler Devise.DeviceCeated, AddressOf Me.OnCreateDevice
Me.oncreateDevice(Devise, Nothing)
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Sub OnCreateDevice(ByVal sender As Object, ByVal e As EventArgs)
Dim dev As Device = CType(sender, Device)
VertexBuffer = New VertexBuffer(GetType(CustomVertex.TransformedColored), 3, dev, 0, CustomVertex.TransformedColored.Format, Pool.Default)
AddHandler VertexBuffer.Created, AddressOf Me.OnCreateVertexBuffer
Me.OnCreateVertexBuffer(VertexBuffer, Nothing)
End Sub
Shared Sub Main()
Dim Form As New Form1()
If Not Form.InitializateGrapfics Then
MessageBox.Show("Direct3D не инициализируется")
Return
End If
Form.Show()
While Form.Created
Form.Render()
Application.DoEvents()
End While
End Sub
Private Sub Render()
If Devise Is Nothing Then
Return
End If
Devise.Clear(ClearFlags.Target, Color.Blue, 1.0F, 0)
Devise.BeginScene()
Devise.SetStreamSource(0, VertexBuffer, 0)
Devise.VertexFormat = VertexFormats.Transformed
Devise.DrawPrimitives(PrimitiveType.TriangleList, 0, 1)
Devise.EndScene()
Devise.Present()
End Sub
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
Me.InitializateGrapfics()
Me.Render()
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
Me.Render()
End Sub
Private Sub OnCreateVertexBuffer(ByVal sender As Object, ByVal e As EventArgs)
Dim vb As VertexBuffer = CType(sender, VertexBuffer)
Dim Verts As CustomVertex.TransformedColored() = CType(vb.Lock(0,0), CustomVertex.TransformedColored)
Verts(0).X = 150
Verts(0).Y = 50
Verts(0).Z = 0.5F
Verts(0).Rhw = 1
Verts(0).Color = System.Drawing.Color.Aqua.ToArgb()
Verts(1).X = 250
Verts(1).Y = 250
Verts(1).Z = 0.5F
Verts(1).Rhw = 1
Verts(1).Color = System.Drawing.Color.Brown.ToArgb()
Verts(2).X = 50
Verts(2).Y = 250
Verts(2).Z = 0.5F
Verts(2).Rhw = 1
Verts(2).Color = System.Drawing.Color.LightPink.ToArgb()
vb.Unlock()
End Sub
End Class
По идее, в итоге он должен выводить треугольник на синем фоне, но он мне выдаёт ошибки в двух местах:
Dim vb As VertexBuffer = CType(sender, VertexBuffer)
Dim Verts As CustomVertex.TransformedColored() = CType(>vb.Lock(0,0)<'вот ашипка, CustomVertex.TransformedColored)
Verts(0).X = 150
и
Devise = New Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, PresentParameters)
AddHandler >Devise.DeviceCeated<'вот ашипка, AddressOf Me.OnCreateDevice
Me.oncreateDevice(Devise, Nothing)
подскажите, пачему у меня Vb ругается?(у меня Vb.net 2008 express edition)
Ответить
|