示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                PresentParams = null;
            }

            if (Direct3D != null)
            {
                Direct3D.Dispose();
                Direct3D = null;
            }
            if (Sprite != null)
            {
                Sprite.Dispose();
                Sprite = null;
            }

            if (Device != null)
            {
                Device.Dispose();
                Device = null;
            }

            if (d3dFont != null)
            {
                d3dFont.Dispose();
                d3dFont = null;
            }
        }
示例#2
0
        private void Form_Load(object sender, EventArgs e)
        {
            Form form = (Form)sender;

            System.Diagnostics.Debug.Assert(Direct3D == null);
            Direct3D = new Direct3D();

            int          nAdapter = Direct3D.Adapters[0].Adapter;
            Capabilities devCaps  = Direct3D.GetDeviceCaps(nAdapter,
                                                           DeviceType.Hardware);

            // the flags for our Direct3D device. Use software rendering by
            // default
            CreateFlags devFlags = CreateFlags.SoftwareVertexProcessing;

            // use hardware vertex processing if supported
            if ((devCaps.DeviceCaps & DeviceCaps.HWTransformAndLight)
                == DeviceCaps.HWTransformAndLight)
            {
                devFlags = CreateFlags.HardwareVertexProcessing;
            }

            // use pure device (whatever that is) if supported
            if ((devCaps.DeviceCaps & DeviceCaps.PureDevice)
                == DeviceCaps.PureDevice)
            {
                devFlags |= CreateFlags.PureDevice;
            }

            DisplayMode displayMode = Direct3D.GetAdapterDisplayMode(nAdapter);

            System.Diagnostics.Debug.Assert(PresentParams == null);
            PresentParams = new PresentParameters();
            PresentParams.BackBufferWidth        = form.ClientSize.Width;
            PresentParams.BackBufferHeight       = form.ClientSize.Height;
            PresentParams.BackBufferFormat       = displayMode.Format;
            PresentParams.BackBufferCount        = 1;
            PresentParams.Windowed               = true;
            PresentParams.SwapEffect             = SwapEffect.Discard;
            PresentParams.AutoDepthStencilFormat = Format.D16;
            PresentParams.EnableAutoDepthStencil = true;
            PresentParams.DeviceWindowHandle     = form.Handle;

            System.Diagnostics.Debug.Assert(Device == null);
            // create the Direct3D device
            Device = new SDXDevice(new Device(Direct3D, nAdapter, DeviceType.Hardware, form.Handle,
                                              devFlags, PresentParams),
                                   Form.ClientSize.Width / 640.0f, Form.ClientSize.Height / 480.0f);

            ResetDevice();

            using (System.Drawing.Font baseFont = new System.Drawing.Font("Arial Black", 18, FontStyle.Bold))
            {
                System.Diagnostics.Debug.Assert(d3dFont == null);
                d3dFont = new Font(Device, baseFont);
            }

            Application.Idle += OnApplicationIdle;
        }