#develop (short for SharpDevelop) is a free IDE for .NET programming languages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

178 lines
4.3 KiB

<?xml version="1.0"?>
<Template originator = "Mike Krueger"
created = "22/01/2003"
lastModified = "11/01/2006">
<!-- Template Header -->
<TemplateConfiguration>
<Name>${res:Templates.Project.Direct3DApplication.Name}</Name>
<Category>C#</Category>
<Subcategory>${res:Templates.File.Categories.WindowsApplications}</Subcategory>
<Icon>C#.Project.FullProject</Icon>
<LanguageName>C#</LanguageName>
<Description>${res:Templates.Project.Direct3DApplication.Description}</Description>
</TemplateConfiguration>
<!-- Actions -->
<Actions>
<Open filename = "MainClass.cs"/>
</Actions>
<!-- Template Content -->
<Combine name = "${ProjectName}" directory = ".">
<Options>
<StartupProject>${ProjectName}</StartupProject>
</Options>
<Project name = "${ProjectName}" directory = ".">
<Options/>
<ProjectItems>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.DirectX" />
<Reference Include="Microsoft.DirectX.Direct3D" />
</ProjectItems>
<Files>
<File name="MainClass.cs"><![CDATA[using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace ${StandardNamespace}
{
/// <summary>
/// This is the main class of my Direct3D application
/// </summary>
public class MainClass : Form
{
/// <summary>
/// The rendering device
/// </summary>
Device device = null;
public MainClass()
{
this.ClientSize = new System.Drawing.Size(640, 480);
this.Text = "Direct3D Project";
}
public bool InitializeGraphics()
{
try {
// Now let's setup the Direct3D stuff
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
// Create the device
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
// Setup the event handlers for the device
device.DeviceLost += new EventHandler(this.InvalidateDeviceObjects);
device.DeviceReset += new EventHandler(this.RestoreDeviceObjects);
device.Disposing += new EventHandler(this.DeleteDeviceObjects);
device.DeviceResizing += new CancelEventHandler(this.EnvironmentResizing);
return true;
} catch (DirectXException) {
return false;
}
}
protected virtual void InvalidateDeviceObjects(object sender, EventArgs e)
{
}
protected virtual void RestoreDeviceObjects(object sender, EventArgs e)
{
}
protected virtual void DeleteDeviceObjects(object sender, EventArgs e)
{
}
protected virtual void EnvironmentResizing(object sender, CancelEventArgs e)
{
}
/// <summary>
/// This method moves the scene
/// </summary>
protected virtual void FrameMove()
{
// TODO : Frame movement
}
/// <summary>
/// This method renders the scene
/// </summary>
protected virtual void Render()
{
if (device != null) {
device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
device.BeginScene();
// TODO : Scene rendering
device.EndScene();
device.Present();
}
}
/// <summary>
/// Our mainloop
/// </summary>
public void Run()
{
// While the form is still valid, render and process messages
while (Created) {
FrameMove();
Render();
Application.DoEvents();
}
}
protected override void OnPaint(PaintEventArgs e)
{
this.Render();
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
if ((int)e.KeyChar == (int)System.Windows.Forms.Keys.Escape) {
this.Close();
}
}
/// <summary>
/// The main entry point for the application
/// </summary>
static void Main()
{
using (MainClass mainClass = new MainClass()) {
if (!mainClass.InitializeGraphics()) {
MessageBox.Show("Error while initializing Direct3D");
return;
}
mainClass.Show();
mainClass.Run();
}
}
}
}
]]></File>
<File name="AssemblyInfo.cs" src="DefaultAssemblyInfo.cs"/>
</Files>
</Project>
</Combine>
</Template>