Device, classe
Mise à jour : novembre 2007
Objet parent de tous les objets graphiques dans la scène.
Espace de noms : Microsoft.WindowsMobile.DirectX.Direct3D
Assembly : Microsoft.WindowsMobile.DirectX (dans Microsoft.WindowsMobile.DirectX.dll)
Syntaxe
'Déclaration
Public Class Device _
Implements IDisposable
'Utilisation
Dim instance As Device
public class Device : IDisposable
public ref class Device : IDisposable
public class Device implements IDisposable
Notes
Un périphérique exécute le rendu sur primitives, crée des ressources, gère des variables au niveau du système, et obtient et définit des palettes.
Exemples
L'exemple de code suivant crée un périphérique.
Public Class Form1
Inherits Form
' Set global variables for this project.
Private device As Device = Nothing
Public Sub New()
' Set the initial size and caption of the form.
Me.ClientSize = New System.Drawing.Size(400, 300)
Me.Text = "D3D Tutorial 01: CreateDevice"
End Sub 'New
Public Function InitializeGraphics() As Boolean
Try
' Set up presentation parameters and create the Direct3D
' device.
Dim presentParams As New PresentParameters()
presentParams.Windowed = True
presentParams.SwapEffect = SwapEffect.Discard
device = New Device(0, DeviceType.Default, Me, CreateFlags.None, presentParams)
Return True
Catch
Return False
End Try
End Function
Private Sub Render()
If device Is Nothing Then
Return
End If
'Clear the backbuffer to a blue color.
device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0F, 0)
'Begin the scene.
device.BeginScene()
'Render scene objects, if desired.
'End the scene.
device.EndScene()
device.Present()
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
' Render on painting.
Me.Render()
End Sub
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
If Fix(System.Convert.ToByte(e.KeyChar)) = Fix(System.Windows.Forms.Keys.Escape) Then
' Handle the ESC key being pressed.
Me.Close()
End If
End Sub
Shared Sub Main()
Dim DeviceForm As New Form1()
Try
If Not DeviceForm.InitializeGraphics() Then
' Initialize Direct3D.
MsgBox("Could not initialize Direct3D. This tutorial will exit.")
Return
End If
DeviceForm.Show()
'While the form is still valid, render and process messages.
'While DeviceForm.Created
' DeviceForm.Render()
' Application.DoEvents()
'End While
Finally
DeviceForm.Dispose()
End Try
End Sub
End Class
public class CreateDevice : Form
{
// Set global variables for this project.
Device device = null;
public CreateDevice()
{
// Set the initial size of the form.
this.ClientSize = new System.Drawing.Size(400, 300);
// Set the caption for the form.
this.Text = "D3D Tutorial 01: CreateDevice";
}
public bool InitializeGraphics()
{
try
{
// Set up presentation parameters and create the
// Direct3D device.
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Default, this, CreateFlags.None, presentParams);
return true;
}
catch (DirectXException)
{
return false;
}
}
private void Render()
{
if (device == null)
return;
//Clear the backbuffer to a blue color.
device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
//Begin the scene.
device.BeginScene();
// Rendering scene objects, if desired.
//End the scene.
device.EndScene();
device.Present();
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
// Render on painting.
this.Render();
}
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{
if ((int)(byte)e.KeyChar == (int)System.Windows.Forms.Keys.Escape)
// Handle the ESC key being pressed.
this.Close();
}
/// <Summary>
/// The main entry point for the application.
/// </Summary>
static void Main()
{
using (CreateDevice DeviceForm = new CreateDevice())
{
// Initialize Direct3D.
if (!DeviceForm.InitializeGraphics())
{
MessageBox.Show("Could not initialize Direct3D. This tutorial will exit.");
return;
}
DeviceForm.Show();
// While the form is still valid, render and process messages.
// while (DeviceForm.Created)
//{
DeviceForm.Render();
Application.DoEvents();
//}
}
}
}
Hiérarchie d'héritage
System.Object
Microsoft.WindowsMobile.DirectX.Direct3D.Device
Sécurité des threads
Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.
Plateformes
Windows CE, Windows Mobile pour Smartphone, Windows Mobile pour Pocket PC
Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.
Informations de version
.NET Compact Framework
Pris en charge dans : 3.5, 2.0
Voir aussi
Référence
Microsoft.WindowsMobile.DirectX.Direct3D, espace de noms
Autres ressources
Programmation Direct3D Mobile dans le .NET Compact Framework