예제 #1
0
        public GL_GameWindow(CreateWindowParams windowParams)
        {
            mCreatePosition = windowParams.WindowPosition;

            if (string.IsNullOrEmpty(windowParams.IconFile) == false)
            {
                mIcon = new System.Drawing.Icon(windowParams.IconFile);
            }
            else
            {
                mIcon = AgateLib.WinForms.FormUtil.AgateLibIcon;
            }

            mTitle       = windowParams.Title;
            mWidth       = windowParams.Width;
            mHeight      = windowParams.Height;
            mAllowResize = windowParams.IsResizable;
            mHasFrame    = windowParams.HasFrame;

            if (windowParams.IsFullScreen)
            {
                CreateFullScreenDisplay();
            }
            else
            {
                CreateWindowedDisplay();
            }

            mDisplay = Display.Impl as GL_Display;
            mDisplay.InitializeGL();

            mDisplay.ProcessEventsEvent += new EventHandler(mDisplay_ProcessEventsEvent);
        }
예제 #2
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                frm = new PixelBufferForm();
                frm.Show();

                DisplayWindow wind = new DisplayWindow(CreateWindowParams.FromControl(frm.panel1));

                image  = new Surface("9ball.png");
                buffer = image.ReadPixels(PixelFormat.RGBA8888);

                Mouse.MouseDown += new InputEventHandler(Mouse_MouseDown);
                Mouse.MouseMove += new InputEventHandler(Mouse_MouseMove);

                while (wind.IsClosed == false)
                {
                    Display.BeginFrame();
                    Display.Clear();

                    image.Draw(imageLocation);

                    Display.EndFrame();
                    Core.KeepAlive();
                }
            }
        }
        private void ChangeDisplayWindow(IResolution resolution)
        {
            currentResolution = resolution;

            var screen = window.Screen;

            var createWindowParams = CreateWindowParams.FullScreen(
                Name, resolution, null);
        }
예제 #4
0
        private void InitDisplay()
        {
            // This will create a display "window" that renders to the graphics
            // control on this form
            DisplayWindow wind = new DisplayWindow(CreateWindowParams.FromControl(pctGraphics));

            // load an image
            string fileName = @"jellybean.png";


            mSurface = new Surface(fileName);
        }
예제 #5
0
        public override DisplayWindowImpl CreateDisplayWindow(CreateWindowParams windowParams)
        {
            return(new GL_DisplayControl(windowParams));

            //if (windowParams.RenderToControl)
            //{
            //    return new GL_DisplayControl(windowParams);
            //}
            //else
            //{
            //    return new GL_GameWindow(windowParams);
            //}
        }
예제 #6
0
        public MDX1_DisplayWindow(CreateWindowParams windowParams)
        {
            mChoosePosition = windowParams.WindowPosition;

            if (windowParams.RenderToControl)
            {
                if (typeof(Control).IsAssignableFrom(windowParams.RenderTarget.GetType()) == false)
                {
                    throw new ArgumentException("The specified render target does not derive from System.Windows.Forms.Control");
                }

                mRenderTarget = (Control)windowParams.RenderTarget;

                mChooseFullscreen = false;
                mChooseWidth      = mRenderTarget.ClientSize.Width;
                mChooseHeight     = mRenderTarget.ClientSize.Height;

                mDisplay = Display.Impl as MDX1_Display;
                mDisplay.Initialize(this);
                mDisplay.VSyncChanged += new EventHandler(mDisplay_VSyncChanged);

                AttachEvents();
                CreateBackBuffer();
            }
            else
            {
                if (string.IsNullOrEmpty(windowParams.IconFile) == false)
                {
                    mIcon = new Drawing.Icon(windowParams.IconFile);
                }

                mTitle            = windowParams.Title;
                mChooseFullscreen = windowParams.IsFullScreen;
                mChooseWidth      = windowParams.Width;
                mChooseHeight     = windowParams.Height;
                mChooseResize     = windowParams.IsResizable;
                mHasFrame         = windowParams.HasFrame;

                CreateWindow(mChooseFullscreen);

                mDisplay = Display.Impl as MDX1_Display;
                mDisplay.Initialize(this);
                mDisplay.VSyncChanged += new EventHandler(mDisplay_VSyncChanged);

                AttachEvents();
                CreateBackBuffer();
            }
        }
        private void ChangeDisplayWindow(IResolution resolution)
        {
            currentResolution = resolution;

            foreach (var window in windows)
            {
                var screen = window.Screen;

                var createWindowParams = CreateWindowParams.FullScreen(
                    Name, resolution, null);

                createWindowParams.TargetScreen = screen;

                windows.Add(new DisplayWindow(createWindowParams));
            }
        }
예제 #8
0
        private bool InitDisplay()
        {
            // This will create a display "window" that renders to the graphics
            // control on this form
            // It doesn't matter if this goes out of scope, because a reference
            // will be maintained by the Display object.
            wind = new DisplayWindow(CreateWindowParams.FromControl(pctGraphics));

            //srcSurf = new Surface();

            SetSprite(new Sprite("attacke.png", 96, 96));

            Display.PackAllSurfaces();

            return(true);
        }
예제 #9
0
        public Form1()
        {
            InitializeComponent();

            Keyboard.KeyDown += new InputEventHandler(Keyboard_KeyDown);
            Keyboard.KeyUp   += new InputEventHandler(Keyboard_KeyUp);

            Mouse.MouseWheel       += new InputEventHandler(Mouse_MouseWheel);
            Mouse.MouseMove        += new InputEventHandler(Mouse_MouseMove);
            Mouse.MouseDown        += new InputEventHandler(Mouse_MouseDown);
            Mouse.MouseUp          += new InputEventHandler(Mouse_MouseUp);
            Mouse.MouseDoubleClick += new InputEventHandler(Mouse_MouseDoubleClickEvent);

            new DisplayWindow(CreateWindowParams.FromControl(agateRenderTarget1));

            Application.Idle += new EventHandler(Application_Idle);
        }
예제 #10
0
        public Drawing_DisplayWindow(DisplayWindow owner, CreateWindowParams windowParams)
        {
            mOwner = owner;

            if (windowParams.RenderToControl == true)
            {
                if (typeof(Control).IsAssignableFrom(windowParams.RenderTarget.GetType()) == false)
                {
                    throw new AgateException(string.Format("The specified render target is of type {0}, " +
                                                           "which does not derive from System.Windows.Forms.Control.", windowParams.RenderTarget.GetType().Name));
                }

                mRenderTarget = (Control)windowParams.RenderTarget;

                AttachEvents();

                RecreateBackBuffer();
            }
            else
            {
                AgateLib.WinForms.FormUtil.InitializeWindowsForm(out frm, out mRenderTarget, windowParams.WindowPosition, windowParams.Title,
                                                                 windowParams.Width, windowParams.Height, windowParams.IsFullScreen, windowParams.IsResizable,
                                                                 windowParams.HasFrame);

                if (string.IsNullOrEmpty(windowParams.IconFile) == false)
                {
                    mIcon    = new Icon(windowParams.IconFile);
                    frm.Icon = mIcon;
                }

                // finally, show the form
                frm.Show();

                AttachEvents();

                // and create the back buffer
                RecreateBackBuffer();
            }

            mFrameBuffer = new Drawing_FrameBuffer(mBackBuffer);
            mFrameBuffer.EndRenderEvent += new EventHandler(mFrameBuffer_EndRenderEvent);
            mFrameBuffer.mAttachedWindow = mOwner;
        }
예제 #11
0
        private void CreateDisplayWindow()
        {
            CreateWindowParams windp;

            if (FullScreen)
            {
                windp = CreateWindowParams.FullScreen(ApplicationTitle,
                                                      WindowSize.Width, WindowSize.Height, 32);

                windp.IconFile = InitParams.IconFile;
            }
            else
            {
                windp = CreateWindowParams.Windowed(ApplicationTitle,
                                                    WindowSize.Width, WindowSize.Height,
                                                    InitParams.AllowResize, InitParams.IconFile);
            }

            mWindow = new DisplayWindow(windp);
        }
예제 #12
0
 public override DisplayWindowImpl CreateDisplayWindow(DisplayWindow owner, CreateWindowParams windowParams)
 {
     return(new SDX_DisplayWindow(owner, windowParams));
 }
예제 #13
0
        internal void Initialize(SDX_DisplayWindow window, CreateWindowParams windowParams)
        {
            if (mInitialized)
            {
                return;
            }

            if (window.RenderTarget.TopLevelControl == null)
            {
                throw new ArgumentException("The specified render target does not have a Form object yet.  " +
                                            "It's TopLevelControl property is null.  You may not create DisplayWindow objects before " +
                                            "the control to render to is added to the Form.");
            }

            mInitialized = true;

            // ok, create D3D device
            PresentParameters present = windowParams.IsFullScreen ?
                                        CreateFullScreenPresentParameters(window, windowParams.Width, windowParams.Height, windowParams.Bpp) :
                                        CreateWindowedPresentParameters(window, 0, 0, 32);

            DeviceType dtype = DeviceType.Hardware;

            int adapterOrdinal = mDirect3Dobject.Adapters.DefaultAdapter.Adapter;

            var caps  = mDirect3Dobject.GetDeviceCaps(adapterOrdinal, Direct3D.DeviceType.Hardware);
            var flags = Direct3D.CreateFlags.SoftwareVertexProcessing;

            // Is there support for hardware vertex processing? If so, replace
            // software vertex processing.
            if ((caps.DeviceCaps & DeviceCaps.HWTransformAndLight) == DeviceCaps.HWTransformAndLight)
            {
                flags = Direct3D.CreateFlags.HardwareVertexProcessing;
            }

            // Does the device support a pure device?
            if ((caps.DeviceCaps & DeviceCaps.PureDevice) == DeviceCaps.PureDevice)
            {
                flags |= Direct3D.CreateFlags.PureDevice;
            }

            Device device = new Device(mDirect3Dobject, adapterOrdinal, dtype,
                                       window.RenderTarget.TopLevelControl.Handle,
                                       flags, present);

            try
            {
                Format f = (Format)device.DepthStencilSurface.Description.Format;
                SetHaveDepthStencil(f);
            }
            catch
            {
                mHasDepth   = true;
                mHasStencil = false;

                SetHaveDepthStencil(Format.D16);
            }

            //device.DeviceLost += new EventHandler(mDevice_DeviceLost);
            //device.DeviceReset += new EventHandler(mDevice_DeviceReset);

            device.SetRenderState(RenderState.StencilEnable, false);
            device.SetRenderState(RenderState.ZEnable, true);

            mDevice = new D3DDevice(device);

            //InitializeShaders();

            mPosColorDecl = SDX_VertexBuffer.CreateVertexDeclaration(device, PositionColor.VertexLayout);
        }
예제 #14
0
        public GL_DisplayControl(CreateWindowParams windowParams)
        {
            mChoosePosition = windowParams.WindowPosition;

            if (windowParams.RenderToControl)
            {
                if (typeof(Control).IsAssignableFrom(windowParams.RenderTarget.GetType()) == false)
                {
                    throw new AgateException(string.Format("The specified render target is of type {0}, " +
                                                           "which does not derive from System.Windows.Forms.Control.", windowParams.RenderTarget.GetType().Name));
                }

                mRenderTarget = (Control)windowParams.RenderTarget;

                if (mRenderTarget.TopLevelControl == null)
                {
                    throw new ArgumentException("The specified render target has not been added to a Form yet.  " +
                                                "Check to make sure that you are creating the DisplayWindow after all controls are added " +
                                                "to the Form.  Do not create a DisplayWindow in a constructor for a UserControl, for example.");
                }

                mChooseFullscreen = false;
                mChooseWidth      = mRenderTarget.ClientSize.Width;
                mChooseHeight     = mRenderTarget.ClientSize.Height;

                mDisplay = Display.Impl as GL_Display;

                CreateContext();

                mDisplay.InitializeGL();

                AttachEvents();
            }
            else
            {
                if (string.IsNullOrEmpty(windowParams.IconFile) == false)
                {
                    mIcon = new Drawing.Icon(windowParams.IconFile);
                }

                mTitle            = windowParams.Title;
                mChooseFullscreen = windowParams.IsFullScreen;
                mChooseWidth      = windowParams.Width;
                mChooseHeight     = windowParams.Height;
                mChooseResize     = windowParams.IsResizable;
                mHasFrame         = windowParams.HasFrame;

                if (mChooseFullscreen)
                {
                    CreateFullScreenDisplay();
                }
                else
                {
                    CreateWindowedDisplay();
                }

                mDisplay = Display.Impl as GL_Display;
                mDisplay.InitializeGL();
            }

            mDisplay.ProcessEventsEvent += new EventHandler(mDisplay_ProcessEventsEvent);
        }
예제 #15
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                LightingTestForm frm = new LightingTestForm();
                frm.Show();

                DisplayWindow wnd = new DisplayWindow(CreateWindowParams.FromControl(frm.agateRenderTarget1));

                Surface image = new Surface("jellybean.png");
                Surface ball  = new Surface("ball.png");
                Point   ballPt;
                double  time = 0;

                image.SetScale(2.0, 2.0);
                ball.DisplayAlignment = OriginAlignment.Center;

                LightManager lights = new LightManager();
                lights.Enabled = true;
                lights.AddPointLight(new Vector3(0, 0, -1), Color.White);
                lights.AddPointLight(new Vector3(0, 0, -1), Color.Yellow);

                Display.VSync = false;

                //lights[0].Ambient = Color.White;
                lights[1].AttenuationConstant  = 0.01f;
                lights[1].AttenuationQuadratic = 5e-7f;

                Mouse.MouseMove += delegate(InputEventArgs e)
                {
                    lights[1].Position =
                        new Vector3(e.MousePosition.X, e.MousePosition.Y, -1);
                };

                while (frm.Visible == true)
                {
                    if (frm.chkMoveLight.Checked)
                    {
                        time += Display.DeltaTime / 1000.0;
                    }


                    ballPt = new Point((int)(120 + 110 * Math.Cos(time)),
                                       (int)(120 + 110 * Math.Sin(time)));

                    lights[0].Position = new Vector3(ballPt.X, ballPt.Y, -1);
                    lights[0].Ambient  = Color.FromArgb(frm.btnAmbient.BackColor.ToArgb());
                    lights[0].Diffuse  = Color.FromArgb(frm.btnDiffuse.BackColor.ToArgb());

                    image.RotationAngleDegrees = (double)frm.nudAngle.Value;

                    Display.BeginFrame();
                    Display.Clear(Color.DarkRed);

                    lights.Enabled = frm.enableLightingCheck.Checked;
                    lights.DoLighting();

                    if (frm.chkSurfaceGradient.Checked)
                    {
                        Gradient g = new Gradient(Color.Red, Color.Blue, Color.Cyan, Color.Green);

                        image.ColorGradient = g;
                    }
                    else
                    {
                        image.Color = Color.White;
                    }

                    image.TesselateFactor = (int)frm.nudTess.Value;

                    image.Draw(50, 50);

                    image.Draw(50 + image.DisplayWidth, 50);
                    image.Draw(50, 50 + image.DisplayHeight);

                    ball.Draw(ballPt);

                    Display.EndFrame();
                    Core.KeepAlive();

                    frm.lblFPS.Text = "FPS: " + Display.FramesPerSecond.ToString("0.00");
                }
            }
        }
예제 #16
0
 public override DisplayWindowImpl CreateDisplayWindow(CreateWindowParams windowParams)
 {
     return(new Drawing_DisplayWindow(windowParams));
 }
예제 #17
0
        ///// <summary>
        ///// Creates a DisplayWindowImpl derived object.
        ///// </summary>
        ///// <param name="title"></param>
        ///// <param name="clientWidth"></param>
        ///// <param name="clientHeight"></param>
        ///// <param name="allowResize"></param>
        ///// <param name="iconFile"></param>
        ///// <param name="startFullscreen"></param>
        ///// <returns></returns>
        //public abstract DisplayWindowImpl CreateDisplayWindow(string title, int clientWidth, int clientHeight, string iconFile, bool startFullscreen, bool allowResize);
        ///// <summary>
        ///// Creates a DisplayWindowImpl derived object.
        ///// </summary>
        //public abstract DisplayWindowImpl CreateDisplayWindow(System.Windows.Forms.Control renderTarget);

        /// <summary>
        /// Creates a DisplayWindowImpl derived object.
        /// </summary>
        /// <param name="windowParams"></param>
        /// <returns></returns>
        public abstract DisplayWindowImpl CreateDisplayWindow(CreateWindowParams windowParams);