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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie problem with DirectX

Status
Not open for further replies.

deltaflyer666

Programmer
Jun 26, 2006
8
GB
I am taking my first foray into DirectX and trying the simple triangle tutorial program, however whenever i run the program i am getting the windows form with a large red X throughout it, below is the code i am using copied straight from the website tutorial so it should work just fine, any ideas as to what i need to do to fix this?

Using the latest DirectX SDK in VS2008 on Windows 7 and have all reference to directx included in my project

Code:
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D

Public Class Form1
    Private device As Direct3D.Device

    Public Sub Initialize()
        Dim present As PresentParameters = New PresentParameters
        present.Windowed = True
        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)
        Me.Height = 500
        Me.Width = 500
        Me.Text = "DirectX Tutorial using Visual Basic"

        Initialize()
    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
        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()
        device.VertexFormat = CustomVertex.TransformedColored.Format
        device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices)
        device.EndScene()

        device.Present()

        Me.Invalidate()
    End Sub
End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top