- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# D:/guillaume/guillara/3D/DXGfx/Backup/SampleSceneLoader/Loader.cs

Go to the documentation of this file.

    00001 //BSD License
    00002 //DXGfx® - http://www.eteractions.com
    00003 //Copyright (c) 2005
    00004 //by Guillaume Randon
    00005 //Permission is hereby granted, free of charge, to any person obtaining a copy of this software
    00006 //and associated documentation files (the "Software"), to deal in the Software without restriction,
    00007 //including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00008 //and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
    00009 //subject to the following conditions:
    00010 //The above copyright notice and this permission notice shall be included in all copies or substantial
    00011 //portions of the Software.
    00012 //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
    00013 //INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
    00014 //AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    00015 //DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00016 //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00017 using System;
    00018 using System.Collections;
    00019 using System.Collections.Generic;
    00020 using System.Text;
    00021 using System.Diagnostics;
    00022 using System.IO;
    00023 using System.Windows.Forms;
    00024 using Microsoft.DirectX;
    00025 using Microsoft.DirectX.Direct3D;
    00026 using Microsoft.Samples.DirectX.UtilityToolkit;
    00027 using Microsoft.DirectX.DirectSound;
    00028 using DXGfxLib;
    00029
    00030 namespace SampleSceneLoader
    00031 {
    00032     class Loader : IFrameworkCallback, IDeviceCreation
    00033     {
    00034         // Variables
    00035         private Framework sampleFramework = null; // Framework for samples
    00036         private Font statsFont = null; // Font for drawing text
    00037         private Sprite textSprite = null; // Sprite for batching text calls
    00038         //private ThirdPersonCamera camera = new ThirdPersonCamera(); // A model viewing camera
    00039         private bool isHelpShowing = true; // If true, renders the UI help text
    00040         private Dialog hud = null; // dialog for standard controls
    00041         private Dialog missionUi = null;
    00042         private Matrix worldCenter;
    00043
    00044         // HUD Ui Control constants
    00045         private const int ToggleFullscreen = 1;
    00046         private const int ToggleReference = 3;
    00047         private const int ChangeDevice = 4;
    00048
    00049         // DXGfxLib related variables
    00050         private OutDoorScene outdoorScene;
    00051         private Matrix computedViewMat;
    00052         private const int MissionText = 1;
    00053
    00054         // Need a soundDevice in order to be able to play sounds.
    00055         private Microsoft.DirectX.DirectSound.Device soundDevice = null;
    00056
    00057         private StateBlock defaultState = null;
    00058
    00059         public string selectedFile = "";
    00060
    00061         #region Creation
    00063         public Loader(Framework f)
    00064         {
    00065             // Store framework
    00066             sampleFramework = f;
    00067             // Create dialogs
    00068             hud = new Dialog(sampleFramework);
    00069             missionUi = new Dialog(sampleFramework);
    00070
    00071             DXGfxManager.GetGlobalInstance().Init(sampleFramework);
    00072         }
    00073         #endregion
    00074
    00075         public void InitSound()
    00076         {
    00077             soundDevice = new Microsoft.DirectX.DirectSound.Device();
    00078             soundDevice.SetCooperativeLevel(this.sampleFramework.Window.Handle, CooperativeLevel.Priority);
    00079         }
    00080
    00087         public bool IsDeviceAcceptable(Microsoft.DirectX.Direct3D.Caps caps, Format adapterFormat, Format backBufferFormat, bool windowed)
    00088         {
    00089             // No fallback, need at least PS1.1
    00090             if (caps.PixelShaderVersion < new Version(1, 1))
    00091                 return false;
    00092
    00093             // Skip back buffer formats that don't support alpha blending
    00094             if (!Manager.CheckDeviceFormat(caps.AdapterOrdinal, caps.DeviceType, adapterFormat,
    00095                 Usage.QueryPostPixelShaderBlending, ResourceType.Textures, backBufferFormat))
    00096                 return false;
    00097
    00098             return true;
    00099         }
    00100
    00109         public void ModifyDeviceSettings(DeviceSettings settings, Microsoft.DirectX.Direct3D.Caps caps)
    00110         {
    00111             // If device doesn't support HW T&L or doesn't support 1.1 vertex shaders in HW
    00112             // then switch to SWVP.
    00113             //if ((!caps.DeviceCaps.SupportsHardwareTransformAndLight) ||
    00114             //    (caps.VertexShaderVersion < new Version(1, 1)))
    00115             if (!caps.DeviceCaps.SupportsHardwareTransformAndLight)
    00116             {
    00117                 settings.BehaviorFlags = CreateFlags.SoftwareVertexProcessing;
    00118                 settings.BehaviorFlags = CreateFlags.MixedVertexProcessing;
    00119             }
    00120             else
    00121             {
    00122                 settings.BehaviorFlags = CreateFlags.HardwareVertexProcessing;
    00123             }
    00124
    00125             // This application is designed to work on a pure device by not using
    00126             // any get methods, so create a pure device if supported and using HWVP.
    00127             if ((caps.DeviceCaps.SupportsPureDevice) &&
    00128                 ((settings.BehaviorFlags & CreateFlags.HardwareVertexProcessing) != 0))
    00129             {
    00130                 // Until the state manager is implemented it is better to keep this commented !!
    00131                 //settings.BehaviorFlags |= CreateFlags.DisableDriverManagement;
    00132                 //settings.BehaviorFlags |= CreateFlags.PureDevice;
    00133             }
    00134             // Debugging vertex shaders requires either REF or software vertex processing
    00135             // and debugging pixel shaders requires REF.
    00136 #if(DEBUG_VS)
    00137             if (settings.DeviceType != DeviceType.Reference )
    00138             {
    00139                 settings.BehaviorFlags &= ~CreateFlags.HardwareVertexProcessing;
    00140                 settings.BehaviorFlags |= CreateFlags.SoftwareVertexProcessing;
    00141             }
    00142 #endif
    00143 #if(DEBUG_PS)
    00144             settings.DeviceType = DeviceType.Reference;
    00145 #endif
    00146
    00147             // For the first device created if its a REF device, optionally display a warning dialog box
    00148             if (settings.DeviceType == DeviceType.Reference)
    00149             {
    00150                 Utility.DisplaySwitchingToRefWarning(sampleFramework, "Sample");
    00151             }
    00152         }
    00153
    00161         private void OnCreateDevice(object sender, DeviceEventArgs e)
    00162         {
    00163             // Initialize the stats font
    00164             statsFont = ResourceCache.GetGlobalInstance().CreateFont(e.Device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,
    00165                 Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch
    00166                 , "Arial");
    00167
    00168             // Define DEBUG_VS and/or DEBUG_PS to debug vertex and/or pixel shaders with the
    00169             // shader debugger. Debugging vertex shaders requires either REF or software vertex
    00170             // processing, and debugging pixel shaders requires REF.  The
    00171             // ShaderFlags.Force*SoftwareNoOptimizations flag improves the debug experience in the
    00172             // shader debugger.  It enables source level debugging, prevents instruction
    00173             // reordering, prevents dead code elimination, and forces the compiler to compile
    00174             // against the next higher available software target, which ensures that the
    00175             // unoptimized shaders do not exceed the shader model limitations.  Setting these
    00176             // flags will cause slower rendering since the shaders will be unoptimized and
    00177             // forced into software.  See the DirectX documentation for more information about
    00178             // using the shader debugger.
    00179             ShaderFlags shaderFlags = ShaderFlags.NotCloneable;
    00180 #if(DEBUG_VS)
    00181             shaderFlags |= ShaderFlags.ForceVertexShaderSoftwareNoOptimizations;
    00182 #endif
    00183 #if(DEBUG_PS)
    00184             shaderFlags |= ShaderFlags.ForcePixelShaderSoftwareNoOptimizations;
    00185 #endif
    00186
    00187             // Before everything let's notify the DXGfxManager
    00188             DXGfxManager.GetGlobalInstance().OnCreateDevice(sender, e);
    00189
    00190             DXGfxManager.GetGlobalInstance().Load(selectedFile);
    00191
    00192             // Setup the camera's view parameters
    00193             DXGfxManager.GetGlobalInstance().CurrentCamera.SetViewParameters(new Vector3(0.0f, 0.0f, -5.0f), Vector3.Empty);
    00194         }
    00195
    00196         private void ProceduralSceneCreation(Microsoft.DirectX.Direct3D.Device device)
    00197         {
    00198             // Let's create our scene
    00199             outdoorScene = DXGfxManager.GetGlobalInstance().NewScene("Sample!!", 1000.0f, 2);
    00200             //AABBox desiredBBox = new AABBox(new BBox(new Vector3(0.0f, 0.0f, 0.0f), 1000.0f));
    00201             //outdoorScene = new OutDoorScene(desiredBBox, 2);
    00202             //outdoorScene.camera = camera;
    00203             outdoorScene.LoadTerrain(device, "newheigthmap.bmp");
    00204
    00205             //Water theWater = new Water(device, 2000, 2000, 10, 10, "water.bmp");
    00206             Water2 theWater = new Water2(2000);
    00207             outdoorScene.SceneWater = theWater;
    00208
    00209             SkyBox theSky = new SkyBox(device, "skybox2.x", 160);
    00210             //outdoorScene.SceneSky = theSky;
    00211
    00212             FrameworkMesh tigerMesh = new FrameworkMesh(device, "tiger.x");
    00213             SceneObject sceneObject = outdoorScene.Attach(tigerMesh);
    00214             DXGfxManager.GetGlobalInstance().CurrentAvatar = new Avatar(sceneObject);
    00215
    00216             Random rand = new Random();
    00217             float tigerx = rand.Next(-500, 500);
    00218             float tigerz = rand.Next(-500, 500);
    00219             float tigery = sceneObject.extents.Y * 0.5f + outdoorScene.GetHeigth(tigerx, tigerz);
    00220
    00221             while (tigery < 35.0f)
    00222             {
    00223                 tigerx = rand.Next(-500, 500);
    00224                 tigerz = rand.Next(-500, 500);
    00225                 tigery = sceneObject.extents.Y * 0.5f + outdoorScene.GetHeigth(tigerx, tigerz);
    00226             }
    00227             sceneObject.WorldMat = Matrix.Translation(tigerx, tigery, tigerz);
    00228
    00229             //ObjectFromObj testObj = new ObjectFromObj();
    00230             //testObj.Load(device, "ZMapper_Elephant.obj");
    00231             //testObj.Position = new Vector3(tigerx + 5.0f, tigery + 5.0f, tigerz + 5.0f);
    00232             //outdoorScene.Attach(testObj);
    00233
    00234             MeshRessource tree = new MeshRessource(device, "sapin.x");
    00236
    00237             for (int i = 0; i < 2000; i++)
    00238             {
    00239                 ObjectFromMeshRessource treeObj = new ObjectFromMeshRessource();
    00240                 treeObj.Attach(tree);
    00241                 float x = rand.Next(-500, 500);
    00242                 float z = rand.Next(-500, 500);
    00243                 float y = outdoorScene.GetHeigth(x, z);
    00244
    00245                 while (y < 35.0f)
    00246                 {
    00247                     x = rand.Next(-500, 500);
    00248                     z = rand.Next(-500, 500);
    00249                     y = outdoorScene.GetHeigth(x, z);
    00250                 }
    00251                 treeObj.Position = new Vector3(x, y, z);
    00252                 outdoorScene.AttachStatic(treeObj);
    00253                 //matrices[i] = Matrix.Translation(x, y, z);
    00254             }
    00255             //Impostor imp = new Impostor();
    00256             //imp.Attach(tree);
    00257
    00258             //ExtendedMaterial[] materials = null;
    00259             //Mesh theMesh = Mesh.FromFile("sapin.x", MeshFlags.SystemMemory, device, out materials);
    00260
    00262             //Texture[] meshTextures = new Texture[materials.Length];
    00263             //Material[] meshMaterials = new Material[materials.Length];
    00264             //for (int i = 0; i < materials.Length; i++)
    00265             //{
    00266             //    meshMaterials[i] = materials[i].Material3D;
    00267             //    // Set the ambient color for the material (D3DX does not do this)
    00268             //    meshMaterials[i].Ambient = meshMaterials[i].Diffuse;
    00269
    00270             //    // Create the texture
    00271             //    meshTextures[i] = ResourceCache.GetGlobalInstance().CreateTextureFromFile(device,
    00272             //                                                                      materials[i].TextureFilename);
    00273             //}
    00274             //outdoorScene.AttachBatch(imp.meshes[0], imp.meshMaterials, imp.meshTextures, matrices);
    00275
    00276
    00277
    00278
    00279
    00280             MeshRessource tour = new MeshRessource(device, "tour.x");
    00281
    00282             for (int i = 0; i < 100; i++)
    00283             {
    00284                 ObjectFromMeshRessource tourObj = new ObjectFromMeshRessource();
    00285                 tourObj.Attach(tour);
    00286                 float x = rand.Next(-500, 500);
    00287                 float z = rand.Next(-500, 500);
    00288                 float y = outdoorScene.GetHeigth(x, z);
    00289
    00290                 while (y < 60.0f)
    00291                 {
    00292                     x = rand.Next(-500, 500);
    00293                     z = rand.Next(-500, 500);
    00294                     y = outdoorScene.GetHeigth(x, z);
    00295                 }
    00296                 Matrix s = Matrix.Scaling(2.0f, 3.0f, 2.0f);
    00297                 tourObj.ApplyLocalTransform(s);
    00298                 tourObj.Position = new Vector3(x, y, z);
    00299                 outdoorScene.AttachStatic(tourObj);
    00300             }
    00301
    00302             DXGfxManager.GetGlobalInstance().CurrentCamera.Person = sceneObject;
    00303             DXGfxManager.GetGlobalInstance().CurrentCamera.camera.positionConstraint = outdoorScene;
    00304             DXGfxManager.GetGlobalInstance().CurrentCamera.Person.positionConstraint = outdoorScene;
    00305         }
    00306
    00314         private void OnResetDevice(object sender, DeviceEventArgs e)
    00315         {
    00316             SurfaceDescription desc = e.BackBufferDescription;
    00317             // Create a sprite to help batch calls when drawing many lines of text
    00318             textSprite = new Sprite(e.Device);
    00319
    00320             // Setup the camera's projection parameters
    00321             DXGfxManager.GetGlobalInstance().OnDeviceReset(sender, e);
    00322
    00323             // Setup UI locations
    00324             hud.SetLocation(desc.Width - 170, 0);
    00325             hud.SetSize(170, 170);
    00326
    00327             // Scene call
    00328             //outdoorScene.DeviceChanged(e.Device);
    00329
    00330             missionUi.SetLocation(0, desc.Height - 120);
    00331             missionUi.SetSize(170, 120);
    00332         }
    00333
    00341         private void OnLostDevice(object sender, EventArgs e)
    00342         {
    00343             if (outdoorScene != null)
    00344             {
    00345                 outdoorScene.CleanOnLostDevice();
    00346             }
    00347
    00348             if (textSprite != null)
    00349             {
    00350                 textSprite.Dispose();
    00351                 textSprite = null;
    00352             }
    00353         }
    00354
    00361         private void OnDestroyDevice(object sender, EventArgs e)
    00362         {
    00363             //meshTextures = null;
    00364             //meshMaterials = null;
    00365
    00366             //if (fullMesh != null)
    00367             //    fullMesh.Dispose();
    00368
    00369             //if ((meshes != null) && (meshes.Length > 0))
    00370             //{
    00371             //    for (int i = 0; i < meshes.Length; i++)
    00372             //    {
    00373             //        if (meshes[i] != null)
    00374             //            meshes[i].Dispose();
    00375             //    }
    00376             //}
    00377             //meshes = null;
    00378         }
    00379
    00386         public void OnFrameMove(Microsoft.DirectX.Direct3D.Device device, double appTime, float elapsedTime)
    00387         {
    00388             // Update the camera's position based on user input
    00389             DXGfxManager.GetGlobalInstance().CurrentInputHandler.FrameMove(elapsedTime);
    00390         }
    00391
    00398         public void OnFrameRender(Microsoft.DirectX.Direct3D.Device device, double appTime, float elapsedTime)
    00399         {
    00400             bool beginSceneCalled = false;
    00401
    00402             if (defaultState == null)
    00403             {
    00404                 defaultState = new StateBlock(device, StateBlockType.All);
    00405                 defaultState.Capture();
    00406             }
    00407
    00409             //Matrix worldMatrix = worldCenter * DXGfxManager.GetGlobalInstance().CurrentCamera.WorldMatrix;
    00410             //computedViewMat = Matrix.Multiply(DXGfxManager.GetGlobalInstance().CurrentCamera.WorldMatrix, DXGfxManager.GetGlobalInstance().CurrentCamera.ViewMatrix);
    00411             //outdoorScene.Update(device, computedViewMat, DXGfxManager.GetGlobalInstance().CurrentCamera.ProjectionMatrix, appTime, elapsedTime);
    00412
    00413             DXGfxManager.GetGlobalInstance().UpdateOutdoorScene(elapsedTime, appTime);
    00414
    00415             defaultState.Apply();
    00416
    00417             // Clear the render target and the zbuffer
    00418             device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, 0x00424B79, 1.0f, 0);
    00419             DXGfxManager.GetGlobalInstance().DrawOutdoorScene();
    00420
    00421             //try
    00422             //{
    00423             //    device.BeginScene();
    00424             //    beginSceneCalled = true;
    00425
    00426             //    // Show scene
    00427             //    device.SetTransform(TransformType.World, DXGfxManager.GetGlobalInstance().CurrentCamera.WorldMatrix);
    00428             //    device.SetTransform(TransformType.View, computedViewMat);
    00429             //    device.SetTransform(TransformType.Projection, DXGfxManager.GetGlobalInstance().CurrentCamera.ProjectionMatrix);
    00430             //    outdoorScene.DrawObjects(device, outdoorScene.currentFrustrum);
    00431
    00432             //    device.RenderState.AlphaBlendEnable = false;
    00433
    00434             //    // Show frame rate
    00435             //    RenderText();
    00436
    00437             //    // Show UI
    00438             //    hud.OnRender(elapsedTime);
    00439             //    missionUi.OnRender(elapsedTime);
    00440             //}
    00441             //finally
    00442             //{
    00443             //    if (beginSceneCalled)
    00444             //        device.EndScene();
    00445             //}
    00446         }
    00447
    00452         private void RenderText()
    00453         {
    00454             TextHelper txtHelper = new TextHelper(statsFont, textSprite, 15);
    00455
    00456             // Output statistics
    00457             txtHelper.Begin();
    00458             txtHelper.SetInsertionPoint(5, 5);
    00459             txtHelper.SetForegroundColor(System.Drawing.Color.Yellow);
    00460             txtHelper.DrawTextLine(sampleFramework.FrameStats);
    00461             txtHelper.DrawTextLine(sampleFramework.DeviceStats);
    00462
    00463             txtHelper.SetForegroundColor(System.Drawing.Color.White);
    00464
    00465             txtHelper.End();
    00466         }
    00467
    00474         private void OnKeyEvent(object sender, System.Windows.Forms.KeyEventArgs e)
    00475         {
    00476             switch (e.KeyCode)
    00477             {
    00478                 case System.Windows.Forms.Keys.F1:
    00479                     isHelpShowing = !isHelpShowing;
    00480                     break;
    00481             }
    00482         }
    00483
    00489         public IntPtr OnMsgProc(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool noFurtherProcessing)
    00490         {
    00491             // Give the dialog a chance to handle the message first
    00492             noFurtherProcessing = hud.MessageProc(hWnd, msg, wParam, lParam);
    00493             if (noFurtherProcessing)
    00494                 return IntPtr.Zero;
    00495
    00496             noFurtherProcessing = missionUi.MessageProc(hWnd, msg, wParam, lParam);
    00497             if (noFurtherProcessing)
    00498                 return IntPtr.Zero;
    00499
    00500             // Pass all remaining windows messages to camera so it can respond to user input
    00501             //DXGfxManager.CurrentCamera.HandleMessages(hWnd, msg, wParam, lParam);
    00502             if (DXGfxManager.GetGlobalInstance().CurrentInputHandler != null)
    00503             {
    00504                 DXGfxManager.GetGlobalInstance().CurrentInputHandler.OnMsgProc(hWnd, msg, wParam, lParam);
    00505             }
    00506
    00507             return IntPtr.Zero;
    00508         }
    00509
    00513         public void InitializeApplication()
    00514         {
    00515             int y = 10;
    00516
    00517             // Initialize the HUD
    00518             Microsoft.Samples.DirectX.UtilityToolkit.Button fullScreen = hud.AddButton(ToggleFullscreen, "Toggle full screen", 35, y, 125, 22);
    00519             Microsoft.Samples.DirectX.UtilityToolkit.Button toggleRef = hud.AddButton(ToggleReference, "Toggle reference (F3)", 35, y += 24, 125, 22);
    00520             Microsoft.Samples.DirectX.UtilityToolkit.Button changeDevice = hud.AddButton(ChangeDevice, "Change Device (F2)", 35, y += 24, 125, 22);
    00521             // Hook the button events for when these items are clicked
    00522             fullScreen.Click += new EventHandler(OnFullscreenClicked);
    00523             toggleRef.Click += new EventHandler(OnRefClicked);
    00524             changeDevice.Click += new EventHandler(OnChangeDevicClicked);
    00525
    00526             // Our own UI
    00527             Microsoft.Samples.DirectX.UtilityToolkit.Button missionText = missionUi.AddButton(MissionText, "Salut!!", 0, 0, 170, 120);
    00528             missionText.Click += new EventHandler(missionText_Click);
    00529         }
    00530
    00531         void missionText_Click(object sender, EventArgs e)
    00532         {
    00533             missionUi.GetButton(MissionText).SetText("Button Clicked!!");
    00534         }
    00535
    00537         private void OnChangeDevicClicked(object sender, EventArgs e)
    00538         {
    00539             sampleFramework.ShowSettingsDialog(!sampleFramework.IsD3DSettingsDialogShowing);
    00540         }
    00541
    00543         private void OnFullscreenClicked(object sender, EventArgs e)
    00544         {
    00545             sampleFramework.ToggleFullscreen();
    00546         }
    00547
    00549         private void OnRefClicked(object sender, EventArgs e)
    00550         {
    00551             sampleFramework.ToggleReference();
    00552         }
    00553
    00558         [STAThread]
    00559         static int Main()
    00560         {
    00561
    00562
    00563             System.Windows.Forms.Application.EnableVisualStyles();
    00564             using (Framework sampleFramework = new Framework())
    00565             {
    00566                 Loader sample = new Loader(sampleFramework);
    00567
    00568                 //OpenFileDialog opfdlg = new OpenFileDialog();
    00569                 //if (opfdlg.ShowDialog() == DialogResult.OK)
    00570                 //{
    00571                 //    sample.selectedFile = opfdlg.FileName;
    00572                 //}
    00573                 sample.selectedFile = "waterscene.xml";
    00574
    00575                 // Set the callback functions. These functions allow the sample framework to notify
    00576                 // the application about device changes, user input, and windows messages.  The
    00577                 // callbacks are optional so you need only set callbacks for events you're interested
    00578                 // in. However, if you don't handle the device reset/lost callbacks then the sample
    00579                 // framework won't be able to reset your device since the application must first
    00580                 // release all device resources before resetting.  Likewise, if you don't handle the
    00581                 // device created/destroyed callbacks then the sample framework won't be able to
    00582                 // recreate your device resources.
    00583                 sampleFramework.Disposing += new EventHandler(sample.OnDestroyDevice);
    00584                 sampleFramework.DeviceLost += new EventHandler(sample.OnLostDevice);
    00585                 sampleFramework.DeviceCreated += new DeviceEventHandler(sample.OnCreateDevice);
    00586                 sampleFramework.DeviceReset += new DeviceEventHandler(sample.OnResetDevice);
    00587
    00588                 sampleFramework.SetWndProcCallback(new WndProcCallback(sample.OnMsgProc));
    00589
    00590                 sampleFramework.SetCallbackInterface(sample);
    00591                 //try
    00592                 //{
    00593
    00594                 // Show the cursor and clip it when in full screen
    00595                 sampleFramework.SetCursorSettings(true, true);
    00596
    00597
    00598
    00599
    00600                 // Initialize
    00601
    00602                 sample.InitializeApplication();
    00603
    00604                 // Initialize the sample framework and create the desired window and Direct3D
    00605                 // device for the application. Calling each of these functions is optional, but they
    00606                 // allow you to set several options which control the behavior of the sampleFramework.
    00607                 sampleFramework.Initialize(true, true, true); // Parse the command line, handle the default hotkeys, and show msgboxes
    00608                 sampleFramework.CreateWindow("Sample: Using DXGfxLib");
    00609                 // Change windows size
    00610                 //sampleFramework.Window.Width = 1024;
    00611                 //sampleFramework.Window.Height = 768;
    00612
    00613                 // Now we should be able to call InitSound (it needs at least that the window be created!)
    00614                 // But we need to do this before the create device because we load the sound when the tiger in created!
    00615                 sample.InitSound();
    00616
    00617                 // Hook the keyboard event
    00618                 sampleFramework.Window.KeyDown += new System.Windows.Forms.KeyEventHandler(sample.OnKeyEvent);
    00619                 sampleFramework.CreateDevice(0, true, Framework.DefaultSizeWidth, Framework.DefaultSizeHeight,
    00620                     sample);
    00621
    00622
    00623
    00624                 // Pass control to the sample framework for handling the message pump and
    00625                 // dispatching render calls. The sample framework will call your FrameMove
    00626                 // and FrameRender callback when there is idle time between handling window messages.
    00627                 sampleFramework.MainLoop();
    00628
    00629                 //                }
    00630                 //#if(DEBUG)
    00631                 //                catch (Exception e)
    00632                 //                {
    00633                 //                    // In debug mode show this error (maybe - depending on settings)
    00634                 //                    sampleFramework.DisplayErrorMessage(e);
    00635                 //#else
    00636                 //            catch
    00637                 //            {
    00638                 //                // In release mode fail silently
    00639                 //#endif
    00640                 //                    // Ignore any exceptions here, they would have been handled by other areas
    00641                 //                    return (sampleFramework.ExitCode == 0) ? 1 : sampleFramework.ExitCode; // Return an error code here
    00642                 //                }
    00643
    00644                 // Perform any application-level cleanup here. Direct3D device resources are released within the
    00645                 // appropriate callback functions and therefore don't require any cleanup code here.
    00646                 return sampleFramework.ExitCode;
    00647             }
    00648         }
    00649     }
    00650 }