reinjan Posted April 28, 2006 Posted April 28, 2006 Hello I'm not new to directx but i just cant figure out how to load a mesh, not even the teapot :'( i have this code that i think has no flaws, but it just wont draw my teapot. can someone help me? Dim device As device Private teapot As Mesh ' the teapot mesh Private teapotColor As Material ' used to color the teapot Private world As Matrix ' positions the teapot in the scene Private view As Matrix ' positions the camera in the scene Private projection As Matrix ' controls scene perspective Private Sub meshes2_teapot_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Show() Me.Select() Dim Err As Boolean = True Try Dim Present As PresentParameters = New PresentParameters With Present .Windowed = True .SwapEffect = SwapEffect.Discard .EnableAutoDepthStencil = True .AutoDepthStencilFormat = DepthFormat.D16 End With projection = Matrix.PerspectiveFovLH((Math.PI / 4.0), Present.BackBufferWidth / Present.BackBufferHeight, 1.0, 100.0) Me.Show() device = New Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, Present) Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True) Catch Err = False End Try If Err = False Then MessageBox.Show("Fout zit in InitializeGraphics") Return End If Do While Me.Created Application.DoEvents() createmesh("C:\Documents and Settings\Reintje\Mijn documenten\Reinjan\informatica en school\GIP\Models") Loop End Sub Private Sub createmesh(ByVal path As String) ' the teapot is available as a static method from Mesh teapot = Mesh.Teapot(device) ' setup the color for the teapot teapotColor = New Material teapotColor.Diffuse = Color.Red teapotColor.Ambient = teapotColor.Diffuse ' set initial values for the view and world transforms view = Matrix.LookAtLH(New Vector3(0, 3.5, -4), New Vector3(0, 0, 0), New Vector3(0, 1, 0)) world = Matrix.Identity ' enable z-buffering device.RenderState.ZBufferEnable = True ' enable lighting device.RenderState.Lighting = True ' set the ambient color device.RenderState.Ambient = Color.Gray ' configure a directional light device.Lights(0).Type = LightType.Directional device.Lights(0).Direction = New Vector3(2.0, -1.0, 0.0) device.Lights(0).Diffuse = Color.White device.Lights(0).Enabled = True device.Lights(0).Update() Dim device2 As Device = device ' clear the device in preparation for rendering device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, _ Color.Black, 1.0, 0) ' begin the scene device.BeginScene() device.Transform.World = world device.Material = teapotColor device.SetTexture(0, Nothing) teapot.DrawSubset(0) device.Transform.View = view device.Transform.Projection = projection device.EndScene() End Sub Quote
ardman Posted May 16, 2006 Posted May 16, 2006 ' do this before your render loop else you'll keep recreating the teapot createmesh("C:\Documents and Settings\Reintje\Mijn documenten\Reinjan\informatica en school\GIP\Models") Do While Me.Created Application.DoEvents() ' clear the device in preparation for rendering device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Black, 1.0, 0) ' begin the scene device.BeginScene() device.Transform.World = world device.Material = teapotColor device.SetTexture(0, Nothing) teapot.DrawSubset(0) device.Transform.View = view device.Transform.Projection = projection device.EndScene() ' New line device.Present() Loop End Sub Private Sub createmesh(ByVal path As String) ' the teapot is available as a static method from Mesh teapot = Mesh.Teapot(device) ' setup the color for the teapot teapotColor = New Material teapotColor.Diffuse = Color.Red teapotColor.Ambient = teapotColor.Diffuse ' set initial values for the view and world transforms view = Matrix.LookAtLH(New Vector3(0, 3.5, -4), New Vector3(0, 0, 0), New Vector3(0, 1, 0)) world = Matrix.Identity ' enable z-buffering device.RenderState.ZBufferEnable = True ' enable lighting device.RenderState.Lighting = True ' set the ambient color device.RenderState.Ambient = Color.Gray ' configure a directional light device.Lights(0).Type = LightType.Directional device.Lights(0).Direction = New Vector3(2.0, -1.0, 0.0) device.Lights(0).Diffuse = Color.White device.Lights(0).Enabled = True device.Lights(0).Update() End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.