Export (0) Print
Expand All

Device Class

The parent object of all graphical objects in the scene.

Namespace: Microsoft.WindowsMobile.DirectX.Direct3D
Assembly: Microsoft.WindowsMobile.DirectX (in microsoft.windowsmobile.directx.dll)

public class Device : IDisposable
public class Device implements IDisposable
public class Device implements IDisposable

A device performs primitive-based rendering, creates resources, handles system-level variables, and gets and sets palettes.

The following code example creates a device.

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 it's caption
        this.Text = "D3D Tutorial 01: CreateDevice";
    }

    public bool InitializeGraphics()
    {
        try
        {
            // Now let's setup our D3D stuff
            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 of scene objects can happen here

        //End the scene
        device.EndScene();
        device.Present();
    }
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        this.Render(); // Render on painting
    }
    protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
    {
        if ((int)(byte)e.KeyChar == (int)System.Windows.Forms.Keys.Escape)
            this.Close(); // Esc was pressed
    }

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main()
    {

        using (CreateDevice DeviceForm = new CreateDevice())
        {
            if (!DeviceForm.InitializeGraphics()) // Initialize Direct3D
            {
                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();
            //}
        }
    }
}

System.Object
   Microsoft.WindowsMobile.DirectX.Direct3D.BaseMesh
    Microsoft.WindowsMobile.DirectX.Direct3D.Device

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft