Reputation: 1
I am using visual basic 2012. I checked many tutorials on the net. i did exactly as were in tutorials, to add reference to directx in visual basic. but when i run my program it some times shows errors, some times it hangs, some times it doesnt shows any thing and compiles.
I think in the tutorials they are using different version of visual basic, but how should i add reference to directx in visual basic, so that it runs fine? the given code should work fine because it is exact as in tutorial. i am using visual basic 2012.
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Imports Microsoft.DirectX.DirectInput
Public Class Form1
Dim runonce As Boolean = True
Dim gamerun As Boolean = True
Dim bkgcolor As Color = Color.Black
Dim d3dev As Direct3D.Device
Dim d3dpp As New PresentParameters ' = New PresentParameters
Dim drawfont As Direct3D.Font
Dim x As Int32
Dim wait As Int32
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
gamerun = False
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If (e.KeyCode = Keys.Escape) Then
gamerun = False
Me.Close()
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim pos As Point
pos.X = 0
pos.Y = 0
Me.Location = pos
Me.Height = 600
Me.Width = 800
Me.Show()
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
If runonce Then
Me.Show()
runonce = False
init()
run()
End If
End Sub
Private Sub init()
d3dpp.DeviceWindow = Me
d3dpp.BackBufferCount = 1
d3dpp.BackBufferFormat = Format.X8R8G8B8
d3dpp.BackBufferHeight = Me.Height
d3dpp.BackBufferWidth = Me.Width
d3dpp.SwapEffect = SwapEffect.Discard
d3dpp.PresentationInterval = PresentInterval.Immediate
d3dpp.Windowed = True
d3dpp.EnableAutoDepthStencil = True
d3dpp.AutoDepthStencilFormat = DepthFormat.D24S8
d3dev = New Direct3D.Device(0, Direct3D.DeviceType.Hardware, Me, CreateFlags.HardwareVertexProcessing, d3dpp)
drawfont = New Direct3D.Font(d3dev, New System.Drawing.Font("IMPACT", 32, FontStyle.Regular, GraphicsUnit.Pixel))
x = 25
wait = 0
End Sub
Private Sub run()
Do While gamerun
d3dev.Clear(ClearFlags.Target, Color.Black, 1, 0)
d3dev.BeginScene()
drawfont.DrawText(Nothing, "TEST", x, 50, Color.DarkCyan)
d3dev.EndScene()
d3dev.Present()
Windows.Forms.Application.DoEvents()
Loop
End Sub
End Class
Upvotes: 0
Views: 2384
Reputation: 41127
The DirectX SDK's only support for Visual Basic .NET is the legacy Managed DirectX 1.1 assemblies. These have not been updated in a very long time, and since they are based on .NET 1.1 they won't work with .NET 4.0 or .NET 4.5. They only work with .NET 2.0/3.x. VB 2012 uses .NET 4.5.
You should consider looking at an alterative like SlimDX or SharpDX.
See DirectX and .NET.
Upvotes: 1