Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why can't I use DirectX9 with visual studio2017

Status
Not open for further replies.

John Alexander

Programmer
Jun 26, 2018
7
0
0
US
I tried many different source codes to display that 3D Triangle using DirectX.dll and DirectX3D.dll. I coded in C#,vb.net and even visual c++ but the program just sits there and doesn't even show the form. I attached the program including all the references.
Here is the source code:

Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D

Public Class Form1
Private device As Direct3D.Device ' this the main DirectX device
Public Sub Initialize()
Dim present As PresentParameters = New PresentParameters
present.Windowed = True 'we?ll draw on a window
present.SwapEffect = SwapEffect.Discard
device = New Direct3D.Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, present)
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True) 'Do not draw form's background
Me.Height = 500
Me.Width = 500
Me.Text = "DirectX Tutorial using Visual Basic"
Initialize()
Me.Show()
End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim vertices As CustomVertex.TransformedColored() = New CustomVertex.TransformedColored(0 To 2) {} 'create an array of vertices
vertices(0).Position = New Vector4(150, 100, 0, 1)
vertices(0).Color = Color.Red.ToArgb 'encode color in Argb
vertices(1).Position = New Vector4(Me.Width / 2 + 100, 100, 0, 1)
vertices(1).Color = Color.Green.ToArgb
vertices(2).Position = New Vector4(250, 300, 0, 1)
vertices(2).Color = Color.Yellow.ToArgb

device.Clear(ClearFlags.Target, Color.Black, 1.0, 0)

device.BeginScene() 'all drawings after this line
device.VertexFormat = CustomVertex.TransformedColored.Format
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices)
device.EndScene() 'all drawings before this line

device.Present()
Me.Invalidate() 'redraw
End Sub
End Class
 
 https://files.engineering.com/getfile.aspx?folder=49ceaae1-eae2-410a-9158-b24c6635d986&file=vbtriangle.vbproj
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top