C#如何调用Direct?
请问如何在C#中调用Direct呢?可不可以给点例子
------解决方案--------------------装对应的sdk
引用MicroSoft.DirectX.就可以了
------解决方案--------------------装上SDK后,,,,,看示例
(SDK root)\Samples\Managed\Direct3D\Tutorials\Tutorial1
Path
Source location: (SDK root)\Samples\Managed\Direct3D\Tutorials\Tutorial1
Procedure
Creating an Application Window
The first thing any Microsoft Windows application must do when run is to create an application window. To do this, the first call in the Main() function of the following sample code is to the constructor of an application-defined CreateDevice class that sets the size of the display window, the caption of the window, and the window icon. CreateDevice is created from the System.Windows.Forms.Form Leave Site class used in the Microsoft .NET Framework to represent a window in an application.
[C#]
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DeviceTutorial
{
public class CreateDevice : Form
{
// Our global variables for this project
Device device = null; // Our rendering device
public CreateDevice()
{
// Set the initial size of our form
this.ClientSize = new System.Drawing.Size(400,300);
// And its caption
this.Text = "D3D Tutorial 01: CreateDevice ";
}
.
.
.
}
.
.
.
}
Initializing the Direct3D Object
After you create the application window, you are ready to initialize the Direct3D object that you will use to render the scene. This process includes creating the object, setting the presentation parameters, and finally creating the Direct3D device.
[C#]
public bool InitializeGraphics()
{
try
{
// Now setup our D3D stuff
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
return true;
}
catch (DirectXException)
{
return false;
}
}
The preceding code sample relies upon a PresentParameters object that is used to set the windows display characteristics. For example, by setting the Windowed property to true, the size of the window displayed is less than full screen. This default small-window format has no menu or child windows, but it includes Minimize, Maximize, and Close buttons common to windowed applications. In this case, the ability to quickly swap back buffer memory into system memory is disabled with the SwapEffect.Discard flag. If the Windowed property is instead false, then the created window is placed above all non-topmost windows and should stay above them, even when the window is deactivated.
The final step in the initialization procedure is to create the Direct3D device. In this example the flags input to the Device(Int32,DeviceType,Control,CreateFlags,PresentParameters[]) specify that a hardware device is preferred, and that vertex processing is to be done in software. Note that if you tell the system to use hardware vertex processing by specifying CreateFlags.HardwareVertexProcessing, you will see a significant performance gain on video cards that support hardware vertex pro