Beispiel #1
0
        void init()
        {
            Microsoft.DirectX.Direct3D.PresentParameters pps = new Microsoft.DirectX.Direct3D.PresentParameters();
            pps.SwapEffect           = Microsoft.DirectX.Direct3D.SwapEffect.Discard;
            pps.Windowed             = true;
            pps.BackBufferCount      = 1;
            pps.PresentationInterval = PresentInterval.One;
            pps.BackBufferFormat     = Format.A8R8G8B8;

            if (GameWindow == null)
            {
                //pps.BackBufferWidth = GameControl.Width;
                //pps.BackBufferHeight = GameControl.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameControl, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            else
            {
                //pps.BackBufferWidth = GameWindow.Width;
                //pps.BackBufferHeight = GameWindow.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameWindow, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            D3DDev.VertexFormat = CustomVertex.PositionColoredTextured.Format;


            //D3DDev.ShowCursor(false);

            DSoundDev = new Microsoft.DirectX.DirectSound.Device();
            if (GameWindow == null)
            {
                DSoundDev.SetCooperativeLevel(GameControl, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }
            else
            {
                DSoundDev.SetCooperativeLevel(GameWindow, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }

            DKeyboardDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard);
            DKeyboardDev.Acquire();

            DMouseDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse);
            DMouseDev.Acquire();

            VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), 6, D3DDev, Usage.None, CustomVertex.PositionColoredTextured.Format, Pool.Managed);

            D3DDev.SetStreamSource(0, VertexBuffer, 0);
            D3DDev.TextureState[0].AlphaOperation = TextureOperation.Modulate;

            Sprite = new Sprite(D3DDev);

            FontDescription fd = new FontDescription();

            fd.FaceName = "新宋体";
            fd.Height   = -12;
            Font2D      = new Microsoft.DirectX.Direct3D.Font(D3DDev, fd);

            Font3D = new System.Drawing.Font("新宋体", 12);
        }
Beispiel #2
0
        void init()
        {
            Microsoft.DirectX.Direct3D.PresentParameters pps = new Microsoft.DirectX.Direct3D.PresentParameters();
            pps.SwapEffect = Microsoft.DirectX.Direct3D.SwapEffect.Discard;
            pps.Windowed = true;
            pps.BackBufferCount = 1;
            pps.PresentationInterval = PresentInterval.One;
            pps.BackBufferFormat = Format.A8R8G8B8;

            if (GameWindow == null)
            {
                //pps.BackBufferWidth = GameControl.Width;
                //pps.BackBufferHeight = GameControl.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameControl, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            else
            {
                //pps.BackBufferWidth = GameWindow.Width;
                //pps.BackBufferHeight = GameWindow.Height;
                D3DDev = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, GameWindow, Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing, pps);
            }
            D3DDev.VertexFormat = CustomVertex.PositionColoredTextured.Format;

            //D3DDev.ShowCursor(false);

            DSoundDev = new Microsoft.DirectX.DirectSound.Device();
            if (GameWindow == null)
            {
                DSoundDev.SetCooperativeLevel(GameControl, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }
            else
            {
                DSoundDev.SetCooperativeLevel(GameWindow, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            }

            DKeyboardDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard);
            DKeyboardDev.Acquire();

            DMouseDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse);
            DMouseDev.Acquire();

            VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), 6, D3DDev, Usage.None, CustomVertex.PositionColoredTextured.Format, Pool.Managed);

            D3DDev.SetStreamSource(0, VertexBuffer, 0);
            D3DDev.TextureState[0].AlphaOperation = TextureOperation.Modulate;

            Sprite = new Sprite(D3DDev);

            FontDescription fd = new FontDescription();
            fd.FaceName = "新宋体";
            fd.Height = -12;
            Font2D = new Microsoft.DirectX.Direct3D.Font(D3DDev, fd);

            Font3D = new System.Drawing.Font("新宋体", 12);
        }