Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        public Font GetFont(System.Drawing.Font font)
        {
            if (Device == null)
            {
                return(null);
            }
            Font result;

            if (!fontCache.TryGetValue(font, out result))
            {
                result          = new Font(Device, font);
                fontCache[font] = result;
            }
            return(result);
        }