home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / Sharpdev / 099bsetup.exe / Direct3DProject.xpt < prev    next >
Extensible Markup Language  |  2003-09-21  |  5KB  |  205 lines

  1. <?xml version="1.0"?>
  2. <Template originator   = "Mike Krueger"
  3.           created      = "22/01/2003"
  4.           lastModified = "22/01/2003">
  5.     
  6.     <!-- Template Header -->
  7.     <TemplateConfiguration>
  8.         <Name>Direct3D Project</Name>
  9.         <Category>C#</Category>
  10.         <Icon>C#.Project.FullProject</Icon>
  11.         <LanguageName>C#</LanguageName>
  12.         <Description>Creates a simple Direct3D Project</Description>
  13.     </TemplateConfiguration>
  14.     
  15.     <!-- Actions -->
  16.     <Actions>
  17.         <Open filename = "MainClass.cs"/>
  18.     </Actions>
  19.     
  20.     <!-- Template Content -->
  21.     <Combine name = "${ProjectName}" directory = ".">
  22.         <Options>
  23.             <StartupProject>${ProjectName}</StartupProject>
  24.         </Options>
  25.         
  26.         <Project name = "${ProjectName}" directory = ".">
  27.             <Options/>
  28.             
  29.             <References>
  30.                 <Reference type="Gac" refto="Microsoft.DirectX, Version=1.0.900.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  31.                 <Reference type="Gac" refto="Microsoft.DirectX.Direct3D, Version=1.0.900.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  32.             </References>
  33.             
  34.             <Files>
  35.                 <File name="MainClass.cs"><![CDATA[using System;
  36. using System.Collections;
  37. using System.ComponentModel;
  38. using System.Drawing;
  39. using System.Windows.Forms;
  40.  
  41. using Microsoft.DirectX;
  42. using Microsoft.DirectX.Direct3D;
  43.  
  44. namespace MyDirect3DProject
  45. {
  46.     /// <summary>
  47.     /// This is the main class of my Direct3D application
  48.     /// </summary>
  49.     public class MainClass : Form
  50.     {
  51.         /// <summary>
  52.         /// The rendering device
  53.         /// </summary>
  54.         Device device = null;
  55.         
  56.         public MainClass()
  57.         {
  58.             this.ClientSize = new System.Drawing.Size(640, 480);
  59.             this.Text = "Direct3D Project";
  60.         }
  61.         
  62.         public bool InitializeGraphics()
  63.         {
  64.             try {
  65.                 // Now let's setup the Direct3D stuff
  66.                 PresentParameters presentParams = new PresentParameters();
  67.                 presentParams.Windowed   = true;
  68.                 presentParams.SwapEffect = SwapEffect.Discard;
  69.                 
  70.                 // Create the device
  71.                 device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
  72.                 
  73.                 // Setup the event handlers for the device
  74.                 device.DeviceLost     += new EventHandler(this.InvalidateDeviceObjects);
  75.                 device.DeviceReset    += new EventHandler(this.RestoreDeviceObjects);
  76.                 device.Disposing      += new EventHandler(this.DeleteDeviceObjects);
  77.                 device.DeviceResizing += new CancelEventHandler(this.EnvironmentResizing);
  78.                 
  79.                 return true;
  80.             } catch (DirectXException) {
  81.                 return false;
  82.             }
  83.         }
  84.         
  85.         protected virtual void InvalidateDeviceObjects(object sender, EventArgs e)
  86.         {
  87.         }
  88.         
  89.         protected virtual void RestoreDeviceObjects(object sender, EventArgs e)
  90.         {
  91.         }
  92.         
  93.         protected virtual void DeleteDeviceObjects(object sender, EventArgs e)
  94.         {
  95.         }
  96.         
  97.         protected virtual void EnvironmentResizing(object sender, CancelEventArgs e)
  98.         {
  99.         }
  100.         
  101.         /// <summary>
  102.         /// This method moves the scene
  103.         /// </summary>
  104.         protected virtual void FrameMove()
  105.         {
  106.             // TODO : Frame movement
  107.         }
  108.         
  109.         /// <summary>
  110.         /// This method renders the scene
  111.         /// </summary>
  112.         protected virtual void Render()
  113.         {
  114.             if (device != null) {
  115.                 device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
  116.                 device.BeginScene();
  117.                 
  118.                 // TODO : Scene rendering
  119.                 
  120.                 device.EndScene();
  121.                 device.Present();
  122.             }
  123.         }
  124.         
  125.         /// <summary>
  126.         /// Our mainloop
  127.         /// </summary>
  128.         public void Run()
  129.         {
  130.             // While the form is still valid, render and process messages
  131.             while (Created) {
  132.                 FrameMove();    
  133.                 Render();
  134.                 Application.DoEvents();
  135.             }
  136.         }
  137.         
  138.         protected override void OnPaint(PaintEventArgs e)
  139.         {
  140.             this.Render();
  141.         }
  142.         
  143.         protected override void OnKeyPress(KeyPressEventArgs e)
  144.         {
  145.             base.OnKeyPress(e);
  146.             if ((int)e.KeyChar == (int)System.Windows.Forms.Keys.Escape) {
  147.                 this.Close(); 
  148.             }
  149.         }
  150.         
  151.         /// <summary>
  152.         /// The main entry point for the application
  153.         /// </summary>
  154.         static void Main()
  155.         {
  156.             using (MainClass mainClass = new MainClass()) {
  157.                 if (!mainClass.InitializeGraphics()) {
  158.                     MessageBox.Show("Error while initializing Direct3D");
  159.                     return;
  160.                 }
  161.                 mainClass.Show();
  162.                 mainClass.Run();
  163.             }
  164.         }
  165.     }
  166. }
  167. ]]></File>
  168.             <File name="AssemblyInfo.cs"><![CDATA[using System.Reflection;
  169. using System.Runtime.CompilerServices;
  170.  
  171. // Information about this assembly is defined by the following
  172. // attributes.
  173. //
  174. // change them to the information which is associated with the assembly
  175. // you compile.
  176.  
  177. [assembly: AssemblyTitle("")]
  178. [assembly: AssemblyDescription("")]
  179. [assembly: AssemblyConfiguration("")]
  180. [assembly: AssemblyCompany("")]
  181. [assembly: AssemblyProduct("")]
  182. [assembly: AssemblyCopyright("")]
  183. [assembly: AssemblyTrademark("")]
  184. [assembly: AssemblyCulture("")]
  185.  
  186. // The assembly version has following format :
  187. //
  188. // Major.Minor.Build.Revision
  189. //
  190. // You can specify all values by your own or you can build default build and revision
  191. // numbers with the '*' character (the default):
  192.  
  193. [assembly: AssemblyVersion("1.0.*")]
  194.  
  195. // The following attributes specify the key for the sign of your assembly. See the
  196. // .NET Framework documentation for more information about signing.
  197. // This is not required, if you don't want signing let these attributes like they're.
  198. [assembly: AssemblyDelaySign(false)]
  199. [assembly: AssemblyKeyFile("")]
  200. ]]></File>
  201.             </Files>
  202.         </Project>
  203.     </Combine>
  204. </Template>
  205.