Шустрый

Профиль
Группа: Участник
Сообщений: 148
Регистрация: 1.9.2005
Репутация: 1 Всего: 1
|
Я вытаскиваю из файлика нужный mesh. Работаю в fullscreen. ВСе рисуется, но при работе с Alt+tab просходит ошибка.. Когда вызываю свернутое окно: Devicelost exception. Почему? Что я не так сделал? Вот мой код. | Код | Imports Microsoft.DirectX Imports Microsoft.DirectX.Direct3D
Imports System.Math Public Class Form1 Private angleZ As Double Private device As Direct3D.Device Dim vertbuff As VertexBuffer Private mesh As Mesh Private lostdevice As Boolean Private meshmaterials As Material Private meshtextures(0) As Texture Dim present As PresentParameters
Public Sub Initialize() present = New PresentParameters present.BackBufferCount = 1 present.BackBufferFormat = Format.A8R8G8B8 present.Windowed = False present.SwapEffect = SwapEffect.Discard present.EnableAutoDepthStencil = True present.AutoDepthStencilFormat = DepthFormat.D16 present.BackBufferWidth = 1024 present.BackBufferHeight = 768 present.FullScreenRefreshRateInHz = 75 present.PresentationInterval = PresentInterval.Default
'present.Windowed = True 'we?ll draw on a window 'present.SwapEffect = SwapEffect.Flip 'discuss later 'present.EnableAutoDepthStencil = True 'present.AutoDepthStencilFormat = DepthFormat.D16
'определяем устройство device = New Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, present) loadmesh() Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True) device.VertexFormat = CustomVertex.PositionNormalColored.Format device.RenderState.Lighting = True 'device.RenderState.Ambient = Color.Red
'определяем освещение device.Lights(0).Type = LightType.Directional device.Lights(0).Diffuse = System.Drawing.Color.Blue device.Lights(0).SpecularColor = Microsoft.DirectX.Direct3D.ColorValue.FromColor(Color.Red) device.Lights(0).Specular = Color.Red device.Lights(0).Direction = New Vector3(0, -1, -1) device.Lights(0).Commit() device.Lights(0).Enabled = True
End Sub
Private Sub loadmesh() Dim mtrl() As ExtendedMaterial mesh = mesh.FromFile("d:\test.x", MeshFlags.Managed Or MeshFlags.IbManaged, device, mtrl) Dim testmaterial As Material = New Material() testmaterial.Ambient = Color.White
testmaterial.Diffuse = Color.Blue testmaterial.Specular = Color.Red testmaterial.SpecularColor = Microsoft.DirectX.Direct3D.ColorValue.FromColor(Color.Red) device.Material = testmaterial
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Height = 800 ' Me.Width = 600 Me.Text = "Первый опыт" Initialize() Me.ClientSize = New Size(800, 600)
End Sub Private Sub setupCamera() 'Работаем с камерой Dim camera_vector As Vector3 camera_vector = New Vector3(angleZ / Math.PI * 2.0F, angleZ / Math.PI * 4.0F, angleZ / Math.PI * 6.0F) device.Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 4, Me.Width / Me.Height, 1.0F, 100.0F) device.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, 100.0F), New Vector3(), New Vector3(1, 1, 0)) device.RenderState.Lighting = True device.Transform.World = Matrix.RotationAxis(camera_vector, angleZ / Math.PI)
End Sub
Private Sub draw(ByVal yaw As Double, ByVal pitch As Double, ByVal roll As Double, ByVal x As Double, ByVal y As Double, ByVal z As Double) device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z) angleZ = angleZ + 0.01F device.RenderState.CullMode = Cull.None
mesh.DrawSubset(0) End Sub
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim result As ResultCode = device.CheckCooperativeLevel If (result = ResultCode.DeviceLost) Then Return End If If (result = ResultCode.DeviceNotReset) Then Try present = New PresentParameters present.BackBufferCount = 1 present.BackBufferFormat = Format.A8R8G8B8 present.Windowed = False present.SwapEffect = SwapEffect.Flip present.EnableAutoDepthStencil = True present.AutoDepthStencilFormat = DepthFormat.D16 present.BackBufferWidth = 1024 present.BackBufferHeight = 768 present.FullScreenRefreshRateInHz = 75 device.Reset(present) result = -1 Catch ex As Exception System.Threading.Thread.Sleep(1000) End Try End If
Try device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0F, 0) Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True) setupCamera() device.BeginScene() 'all drawings after this line draw(0.0F, 0.0F, 0.0F + angleZ, 0.0F, 0.0F, 0.0F) draw(0.0F, 0.0F, 0.0F - angleZ, 0.0F, 50.0F, 0.0F) device.EndScene() 'all drawings before this line device.Present() Me.Invalidate() Catch End Try
End Sub
End Class
|
|